Closed
Description
- asyncpg version: 0.17.0
- PostgreSQL version: 10.3
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce
the issue with a local PostgreSQL install?: reproduced with a local install - Python version: 3.6.5
- Platform: Linux x86_64
- Do you use pgbouncer?: no
- Did you install asyncpg with pip?: yes
from datetime import datetime
import asyncio
import asyncpg
async def main():
pool = await asyncpg.create_pool(
database='postgres',
user='postgres',
host='127.0.0.1',
password='1234',
port=2000
)
async with pool.acquire() as connection:
dt_in = datetime(1970, 1, 1, 20, 31, 23, 648000)
dt_out = await connection.fetchval("SELECT '%s'::timestamp" % dt_in)
op = '==' if dt_in == dt_out else '!='
print('%s %s %s' % (dt_in, op, dt_out))
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Output:
1970-01-01 20:31:23.648000 != 1970-01-01 20:31:24.648000
But in psql all works fine:
postgres=# select '1970-01-01 20:31:23.648000'::timestamp;
timestamp
-------------------------
1970-01-01 20:31:23.648
(1 row)
I guess there is a problem with time parsing in asyncpg.
Maybe seconds were rounded somewhere, like this:
>>> d
datetime.datetime(1970, 1, 1, 20, 31, 23, 648000)
>>> d.timestamp()
63083.648
>>> int(d.timestamp()) % 60
23
>>> round(d.timestamp()) % 60
24
Metadata
Metadata
Assignees
Labels
No labels