Last active
January 31, 2024 18:36
-
-
Save lupko/336da65b37aade5dc2433004e2720d8e to your computer and use it in GitHub Desktop.
NUMERIC values are corrupted in results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import adbc_driver_postgresql.dbapi | |
_USERNAME = "..." | |
_PASSWORD = "..." | |
_DATABASE = "..." | |
# tried values from 0 to 15. summary: | |
# | |
# 0 - 4: ok | |
# 5 - corrupt | |
# 6 - ok | |
# 7 - ok | |
# 8 - ok | |
# 9 - corrupt | |
# 10 - corrupt | |
# 11 - ok | |
# 12 - ok | |
# 13 - corrupt | |
# 14 - corrupt | |
# 15 - corrupt | |
_DECIMAL = 5 | |
_INIT = [ | |
"DROP TABLE numeric_test;", | |
f"CREATE TABLE numeric_test (col numeric(16, {_DECIMAL}));", | |
"""INSERT INTO numeric_test VALUES | |
(0.0), | |
(1.0), | |
(1.01), | |
(1.012), | |
(1.0123), | |
(1.01234), | |
(1.012345), | |
(1.0123456), | |
(1.01234567), | |
(1.012345678), | |
(1.0123456789), | |
(1.0123456789);""" | |
] | |
print(f"adbc_driver_postgresql {adbc_driver_postgresql.__version__}") | |
with adbc_driver_postgresql.dbapi.connect(f"postgresql://{_USERNAME}:{_PASSWORD}@localhost:5432/{_DATABASE}") as conn: | |
with conn.cursor() as c: | |
# PostgreSQL 16.1 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 13.2.1 20231011 (Red Hat 13.2.1-4), 64-bit | |
c.execute("SELECT version();") | |
print(c.fetchone()[0]) | |
for stmt in _INIT: | |
c.execute(stmt) | |
with conn.cursor() as c: | |
c.execute("SELECT * FROM numeric_test;") | |
results = c.fetch_arrow_table() | |
col = results.column(0) | |
for i in range(results.num_rows): | |
try: | |
print(f"row {i:03}: |{col[i]}|") | |
except UnicodeError: | |
print(f"Unicode encode error for row {i}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment