Skip to content

Commit

Permalink
Issue #1020 Infinity numeric support (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
krokoziabla authored Oct 8, 2023
1 parent f21ebf6 commit 0c3bf60
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion asyncpg/pgproto
35 changes: 25 additions & 10 deletions tests/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,17 +633,32 @@ async def test_numeric(self):
"SELECT $1::numeric", decimal.Decimal('sNaN'))
self.assertTrue(res.is_nan())

with self.assertRaisesRegex(asyncpg.DataError,
'numeric type does not '
'support infinite values'):
await self.con.fetchval(
"SELECT $1::numeric", decimal.Decimal('-Inf'))
if self.server_version < (14, 0):
with self.assertRaisesRegex(
asyncpg.DataError,
'invalid sign in external "numeric" value'
):
await self.con.fetchval(
"SELECT $1::numeric", decimal.Decimal('-Inf'))

with self.assertRaisesRegex(asyncpg.DataError,
'numeric type does not '
'support infinite values'):
await self.con.fetchval(
"SELECT $1::numeric", decimal.Decimal('+Inf'))
with self.assertRaisesRegex(
asyncpg.DataError,
'invalid sign in external "numeric" value'
):
await self.con.fetchval(
"SELECT $1::numeric", decimal.Decimal('+Inf'))

with self.assertRaisesRegex(asyncpg.DataError, 'invalid'):
await self.con.fetchval(
"SELECT $1::numeric", 'invalid')
else:
res = await self.con.fetchval(
"SELECT $1::numeric", decimal.Decimal("-Inf"))
self.assertTrue(res.is_infinite())

res = await self.con.fetchval(
"SELECT $1::numeric", decimal.Decimal("+Inf"))
self.assertTrue(res.is_infinite())

with self.assertRaisesRegex(asyncpg.DataError, 'invalid'):
await self.con.fetchval(
Expand Down

0 comments on commit 0c3bf60

Please sign in to comment.