pgsql 有一个库, 里面有多个模式, 每个模式下可能有相同的表, 如何获取表的主键
SELECT
tc.table_schema AS 模式,
tc.table_name AS 表名,
kcu.column_name AS 列名
FROM
information_schema.table_constraints AS tc
JOIN
information_schema.key_column_usage AS kcu
ON tc.constraint_name = kcu.constraint_name
AND tc.table_schema = kcu.table_schema
WHERE
tc.constraint_type = 'PRIMARY KEY' and tc.table_schema = 'sz' and tc.table_name ='dict'
ORDER BY
tc.table_schema,
tc.table_name,
kcu.ordinal_position;