Skip to content

Got an unexpected number of seconds in datetime from asyncpg#363

@rossnomann

Description

@rossnomann
  • 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
fromdatetimeimportdatetimeimportasyncioimportasyncpgasyncdefmain(): pool=awaitasyncpg.create_pool( database='postgres', user='postgres', host='127.0.0.1', password='1234', port=2000 ) asyncwithpool.acquire() asconnection: dt_in=datetime(1970, 1, 1, 20, 31, 23, 648000) dt_out=awaitconnection.fetchval("SELECT '%s'::timestamp"%dt_in) op='=='ifdt_in==dt_outelse'!='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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions