On 12/5/24 18:00, Adrian Klaver wrote:
On 12/5/24 17:37, Adrian Klaver wrote:
On 12/5/24 17:27, Daniel Johnson wrote:

You might try something like:

NOW() + INTERVAL || ' ' ||  %(NextDBLog)s || ' SECOND'

If that does work then you will need to use the psycopg.sql module to build that part of the query



What I ended getting to work:

from psycopg import sql

cur.execute(sql.SQL("select now(), now() + ({} || ' seconds')::interval ").format(sql.Literal(4)))

cur.fetchone()
(datetime.datetime(2024, 12, 5, 17, 57, 55, 670218, tzinfo=zoneinfo.ZoneInfo(key='US/Pacific')),  datetime.datetime(2024, 12, 5, 17, 57, 59, 670218, tzinfo=zoneinfo.ZoneInfo(key='US/Pacific')))



Then there is the alternative I keep forgetting about, the function make_interval():

https://www.postgresql.org/docs/current/functions-datetime.html

make_interval ( [ years int [, months int [, weeks int [, days int [, hours int [, mins int [, secs double precision ]]]]]]] ) → interval

Then you could pass parameters to the function.

--
Adrian Klaver
adrian.kla...@aklaver.com



Reply via email to