Question Details

No question body available.

Tags

python postgresql psycopg2 psycopg3

Answers (1)

February 7, 2026 Score: 1 Rep: 27,368 Quality: Low Completeness: 50%

Found a way, by calling asstring on the sql.Identifier before passing it to sql.Literal

import psycopg
import psycopg.sql as sql

with psycopg.connect('postgresql://postgres:postgres@127.0.0.1:5432') as conn: with conn.cursor() as cursor: cursor.execute(sql.SQL(''' SELECT * FROM pg
inherits WHERE inhparent = {identifier}::regclass ''').format(identifier=sql.Literal( sql.Identifier('myschema', 'mytable').as_string(conn) )))