public inbox for [email protected]  
help / color / mirror / Atom feed
From: Adrian Klaver <[email protected]>
To: Daniel Johnson <[email protected]>
To: [email protected]
Subject: Re: Parameter in SQL query being misinterpreted
Date: Thu, 5 Dec 2024 18:15:43 -0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<[email protected]>

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
[email protected]






view thread (6+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Parameter in SQL query being misinterpreted
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox