Код: Выделить всё
'"my_schema_name"."my_table_name"'::regclass
Если я попробую это:
Код: Выделить всё
import psycopg2
import psycopg2.sql as sql
with psycopg2.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.Identifier('my_schema', 'my_table')))
Код: Выделить всё
psycopg2.errors.UndefinedTable: missing FROM-clause entry for table "my_schema"
LINE 4: WHERE inhparent = "my_schema"."my_table"::regcla...
Код: Выделить всё
import psycopg2
import psycopg2.sql as sql
with psycopg2.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('my_schema', 'my_table'))))
Код: Выделить всё
psycopg2.ProgrammingError: can't adapt type 'Identifier'
Код: Выделить всё
(quote_ident({schema_name}) || '.' || quote_ident({table_name}))::regclass
Поэтому я хотел бы безопасно сгенерировать '"my_schema"."my_table_name"'::regclass (и если ничего другого, просто из любопытства, как это сделать!)
Контекст таков, что я создаю пакет Python, который проверяет/управляет разрешения в PostgreSQL для произвольных таблиц.
Подробнее здесь: https://stackoverflow.com/questions/798 ... or-casting
Мобильная версия