Re: Parameter in SQL query being misinterpreted - Mailing list psycopg

From Daniel Johnson
Subject Re: Parameter in SQL query being misinterpreted
Date
Msg-id 3143b3b4-c22c-4fed-ab6c-aa371a3cd288@progman.us
Whole thread Raw
In response to Re: Parameter in SQL query being misinterpreted  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
List psycopg
On 12/5/24 20:39, Daniele Varrazzo wrote:
<snip>
> Adrian has already provided a few workarounds for the problem you
> report - thank you very much!. The one I prefer is however the
> following, because it does without string operations: it makes use of
> the possibility to multiply an interval by a scalar:
> 
>      >>> cur.execute("select now(), now() + %s * '1 second'::interval",
> (10,)).fetchone()
>      (datetime.datetime(2024, 12, 6, 2, 33, 32, 117134,
> tzinfo=zoneinfo.ZoneInfo(key='Europe/London')),
>       datetime.datetime(2024, 12, 6, 2, 33, 42, 117134,
> tzinfo=zoneinfo.ZoneInfo(key='Europe/London')))

Oh I hadn't even thought about multiplying an interval, that's a very 
clean approach.  Prior to e-mailing the list I'd tried something similar 
to (but not as thorough as) Adrian's suggestion and it had failed, but 
if it works I like the look of this.

I vaguely recall having a similar interval manipulation headache in a 
PHP portion of this project, I shall try the same thing there.

Thank you so much!

Daniel Johnson
djohnson@progman.us




psycopg by date:

Previous
From: Daniele Varrazzo
Date:
Subject: Re: Parameter in SQL query being misinterpreted
Next
From: YoungUk Song
Date:
Subject: Best Practices for Checking PostgreSQL Server Mode with Multiple Connections