Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: NUMERIC vs BIGNUMERIC column type selection based on precision and scale #1165

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions sqlalchemy_bigquery/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,11 +630,12 @@ def visit_NUMERIC(self, type_, **kw):
else:
suffix = ""

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

visit_DECIMAL = visit_NUMERIC
Expand Down