-
Notifications
You must be signed in to change notification settings - Fork 419
Implement binary format codec for numeric type #168
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
Conversation
83f69af
to
6b6d554
Compare
tests/test_codecs.py
Outdated
"SELECT $1::numeric", decimal.Decimal('NaN')) | ||
self.assertTrue(res.is_nan()) | ||
|
||
with self.assertRaisesRegex(ValueError, 'numeric type does not ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Python also supports signalling NaN (sNaN
) -- add a check that we handle it with a proper exception. Or maybe we should convert Python's sNaN to pg NaN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than a sNaN thing, lgtm.
I tested this version on a bunch of different values and tests passed: import asyncpg
import asyncio
#import uvloop
#asyncio.set_event_loop(uvloop.new_event_loop())
loop = asyncio.get_event_loop()
from decimal import Decimal
async def run(value):
conn = await asyncpg.connect(user='postgres')
await conn.execute('create temporary table temp_table (c1 numeric(6,3))')
await conn.copy_records_to_table('temp_table', records=[(value,)])
return await conn.fetchrow('select c1 from temp_table')
for value in [123, -999, 0.123, -999.999, Decimal('0.123'), Decimal('-0.001'), Decimal('-0.0009'), None]:
print('Testing:', repr(value))
row = loop.run_until_complete(run(value))
print('Result:', repr(row[0]))
print() Output:
The only thing I noticed is that when selecting column back from table returned |
Thanks for catching this. I pushed an updated version that fixes this. |
Thank you Elvis! I retested and now fetched Decimal precision is correct. |
Fixes: #157