From ba7e1e9182aa0fb4d08a27c87cef853584a6f497 Mon Sep 17 00:00:00 2001
From: Clayton J Roberts <claytonjroberts@icloud.com>
Date: Fri, 14 Feb 2025 15:34:20 -0500
Subject: [PATCH 1/2] Fix: NUMERIC vs BIGNUMERIC column type selection based on
 precision and scale

---
 sqlalchemy_bigquery/base.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/sqlalchemy_bigquery/base.py b/sqlalchemy_bigquery/base.py
index 7f4102fa..9e03425f 100644
--- a/sqlalchemy_bigquery/base.py
+++ b/sqlalchemy_bigquery/base.py
@@ -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

From 03d2e7dc95b9605da2a6e587416ec2e19c61d991 Mon Sep 17 00:00:00 2001
From: Clayton J Roberts <claytonjroberts@icloud.com>
Date: Fri, 14 Feb 2025 15:34:20 -0500
Subject: [PATCH 2/2] Fix: NUMERIC vs BIGNUMERIC column type selection based on
 precision and scale

---
 sqlalchemy_bigquery/base.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/sqlalchemy_bigquery/base.py b/sqlalchemy_bigquery/base.py
index 7f4102fa..9e03425f 100644
--- a/sqlalchemy_bigquery/base.py
+++ b/sqlalchemy_bigquery/base.py
@@ -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