public inbox for [email protected]  
help / color / mirror / Atom feed
From: Daniele Varrazzo <[email protected]>
To: Psycopg <[email protected]>
Subject: Python 3.14, template-strings, and psycopg
Date: Sat, 26 Apr 2025 02:25:47 +0200
Message-ID: <CA+mi_8YCc9pwke8Pd6V8U-3SHVta-yAk-2Wt1BJ1aWCkQo9iRQ@mail.gmail.com> (raw)

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






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]
  Subject: Re: Python 3.14, template-strings, and psycopg
  In-Reply-To: <CA+mi_8YCc9pwke8Pd6V8U-3SHVta-yAk-2Wt1BJ1aWCkQo9iRQ@mail.gmail.com>

* 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