From: | Daniel Johnson <djohnson(at)progman(dot)us> |
---|---|
To: | psycopg(at)lists(dot)postgresql(dot)org |
Subject: | Re: Parameter in SQL query being misinterpreted |
Date: | 2024-12-06 23:21:10 |
Message-ID: | 3143b3b4-c22c-4fed-ab6c-aa371a3cd288@progman.us |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)progman(dot)us
From | Date | Subject | |
---|---|---|---|
Next Message | YoungUk Song | 2024-12-08 12:45:34 | Best Practices for Checking PostgreSQL Server Mode with Multiple Connections |
Previous Message | Daniele Varrazzo | 2024-12-06 02:39:31 | Re: Parameter in SQL query being misinterpreted |