Reflected NUMERIC columns lose their precision and scale

Aperta
#313 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

@olpa ci sta già lavorando.

Dal 24/11/2026.

  • #341 di @olpa — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
postgresql, python, sqlalchemy
Ambito
backend, databases

Direzione di ricerca

Look at the reflection code in the dialect, likely in a file like dialect.py or reflection.py. The issue mentions reading from information_schema.columns; find where column types are constructed. You'll need to add reading of numeric_precision and numeric_scale when both are present. Test with a CrateDB instance to ensure the reflected column retains its precision and scale. Check for any existing tests for numeric column reflection.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

When SQLAlchemy reflects a table, this dialect reads each column's type from information_schema.columns. It asks only for data_type, which holds the bare type name: numeric (and nothing else). The precision and scale sit in two other columns, numeric_precision and numeric_scale, which the dialect never reads. So the column comes back as a bare NUMERIC:

reflected NUMERIC(10, 2)   NUMERIC()

Two things go wrong because of it:

  1. The read value is correct, but its form changes slightly: SQLAlchemy formats it with the column's scale, and without one it falls back to ten decimal places.
read a stored 1.25         Decimal('1.2500000000')    # reads with default 10 precision
  1. Creating the column needs the precision, because crate refuses a NUMERIC column without one, so the dialect raises CompileError before sending the DDL.
CREATE TABLE from it       CompileError: CrateDB stores a NUMERIC column only with a precision, as in Numeric(precision=10, scale=2)

crate reports the precision today and that we could implement immediately (in theory), but the scale only comes with crate/crate#20275, which is planned for 6.4.6, so the dialect's reflection should read both (this ticket) only once it ships.

Also, it should only use them only when both are present.

An older server reports NUMERIC(10, 2) as precision 10 with a null scale, and reading that as NUMERIC(10) would drop the decimals of copied tables.

Arrays of NUMERIC report neither value even with that fix (see the example here => so reflected arrays stay without precision for now.

Lingua principale
Python
Stelle
9
Fork
6
Merge medio
6g 13h
PR unite (30g)
8

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di crate/sqlalchemy-cratedb

Tutte le issue di crate/sqlalchemy-cratedb

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.