Python 3.14, template-strings, and psycopg

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Psycopg <psycopg(at)postgresql(dot)org>
Subject: Python 3.14, template-strings, and psycopg
Date: 2025-04-26 00:25:47
Message-ID: CA+mi_8YCc9pwke8Pd6V8U-3SHVta-yAk-2Wt1BJ1aWCkQo9iRQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: psycopg

Hello,

Python 3.14, scheduled for release in October, introduces Template
Strings (https://peps.python.org/pep-0750/) which might be useful to
compose query parameters in a very elegant way, while ensuring safety:

value = 42
cur.execute(t"select * from mytable where id = {value}")

I have started to think about a few details about the feature, such as
whether to allow non-values parts of the query too in the parameters,
for example allowing to use:

value = 42
table_name = sql.Identifier("mytable")
cur.execute(t"select * from {table_name} where id = {value}")

to which we would merge the table name client-side and the value server-side.

I have written some thoughts in
<https://github.com/psycopg/psycopg/discussions/1044>. if anyone would
like to express their opinion about the design of this feature, you
are very welcome.

Thank you very much!

-- Daniele

Browse psycopg by date

  From Date Subject
Next Message Daniele Varrazzo 2025-05-05 11:58:01 Fwd: psycopg Chinese domains and internet keyword
Previous Message Vladimir Ryabtsev 2024-12-21 21:52:40 Re: Memory