Skip to content

Commit ba7e1e9

Browse files
Fix: NUMERIC vs BIGNUMERIC column type selection based on precision and scale
1 parent 8e59f64 commit ba7e1e9

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sqlalchemy_bigquery/base.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,12 @@ def visit_NUMERIC(self, type_, **kw):
630630
else:
631631
suffix = ""
632632

633+
# From the GCP Console for BQ when creating a NUMERIC column:
634+
# > precision and scale for NUMERIC must be: 0 <= precision - scale <= 29
633635
return (
634-
"BIGNUMERIC"
635-
if (type_.precision is not None and type_.precision > 38)
636-
or (type_.scale is not None and type_.scale > 9)
637-
else "NUMERIC"
636+
"NUMERIC"
637+
if (0 <= (type_.precision or 0) - (type_.scale or 0) <= 29)
638+
else "BIGNUMERIC"
638639
) + suffix
639640

640641
visit_DECIMAL = visit_NUMERIC

0 commit comments

Comments
 (0)