Are there plans to add support for using t-strings (introduced with PEP 750 in Python 3.14) for parameterized queries?
Currently doing a parameterized queries looks somewhat like this:
per_id = 42
cursor.execute("select * from person where per_id=:per_id", per_id=per_id)
The code contains the part per_id four times. Using t-strings can reduce this to two:
per_id = 42
cursor.execute(t"select * from person where per_id={per_id}")
psycopg supports t-string too: https://www.psycopg.org/psycopg3/docs/basic/tstrings.html
A function that executes Oracle queries specified as t-strings might look like this:
def execute(cursor, template):
query = []
args = {}
for part in template:
if isinstance(part, str):
query.append(part)
else:
argname = f"p{len(args)+1}"
query.append(f":{argname}")
args[argname] = part.value
return cursor.exexute("".join(query), args)
and can be called like this:
execute((cursor, t"select * from person where per_id={per_id}")
Are there plans to add support for using t-strings (introduced with PEP 750 in Python 3.14) for parameterized queries?
Currently doing a parameterized queries looks somewhat like this:
The code contains the part
per_idfour times. Using t-strings can reduce this to two:psycopgsupports t-string too: https://www.psycopg.org/psycopg3/docs/basic/tstrings.htmlA function that executes Oracle queries specified as t-strings might look like this:
and can be called like this: