Skip to content

Commit aa59023

Browse files
author
Jim Fulton
authored
fix: add DECIMAL and BIGDECIMAL as aliases for NUMERIC and BIGNUMERIC (#638)
* Added decimal types to SqlTypeNames and SqlParameterScalarTypes * Go ahead and alias on the client To convey to the observant that these are aliases, even though they could be used (more or less) directly. * Make sure that DECIMAL data are converted when making API calls. This is mainly as a backstop -- DECIMAL requests should be converted to NUMERIC. * blacken
1 parent 5df63fd commit aa59023

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

google/cloud/bigquery/_helpers.py

+5
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,11 @@ def _time_to_json(value):
363363
"DATETIME": _datetime_to_json,
364364
"DATE": _date_to_json,
365365
"TIME": _time_to_json,
366+
# Make sure DECIMAL and BIGDECIMAL are handled, even though
367+
# requests for them should be converted to NUMERIC. Better safe
368+
# than sorry.
369+
"DECIMAL": _decimal_to_json,
370+
"BIGDECIMAL": _decimal_to_json,
366371
}
367372

368373

google/cloud/bigquery/enums.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ class SqlTypeNames(str, enum.Enum):
203203
INT64 = "INTEGER"
204204
FLOAT = "FLOAT"
205205
FLOAT64 = "FLOAT"
206-
NUMERIC = "NUMERIC"
207-
BIGNUMERIC = "BIGNUMERIC"
206+
DECIMAL = NUMERIC = "NUMERIC"
207+
BIGDECIMAL = BIGNUMERIC = "BIGNUMERIC"
208208
BOOLEAN = "BOOLEAN"
209209
BOOL = "BOOLEAN"
210210
GEOGRAPHY = "GEOGRAPHY" # NOTE: not available in legacy types
@@ -227,6 +227,8 @@ class SqlParameterScalarTypes:
227227
FLOAT64 = ScalarQueryParameterType("FLOAT64")
228228
NUMERIC = ScalarQueryParameterType("NUMERIC")
229229
BIGNUMERIC = ScalarQueryParameterType("BIGNUMERIC")
230+
DECIMAL = ScalarQueryParameterType("NUMERIC")
231+
BIGDECIMAL = ScalarQueryParameterType("BIGNUMERIC")
230232
BOOLEAN = ScalarQueryParameterType("BOOL")
231233
BOOL = ScalarQueryParameterType("BOOL")
232234
GEOGRAPHY = ScalarQueryParameterType("GEOGRAPHY")

0 commit comments

Comments
 (0)