PostgreSQL 12 - 列出与其相关 table 名称不匹配的序列

PostgreSQL 12 - List sequences that do not match their related table name

我有一个包含大量表的数据库。

由于表的名称更改,我想整理不再适合名称的关系。

我能够修复约束,但我无法将这些行放在一起以列出序列和相关列。由于 pgAdmin 在依赖项下显示序列连接到的列,因此应该可以创建一个 SELECT 来显示序列及其相关列。

试试这个:

SELECT a.attrelid::regclass AS table_name,
       a.attname AS column_name,
       pg_get_serial_sequence(a.attrelid::regclass::text, a.attname) AS sequence_name
FROM pg_attribute AS a
   JOIN pg_class AS t ON a.attrelid = t.oid
WHERE t.relkind IN ('r', 'P')
  AND NOT a.attisdropped
  AND pg_get_serial_sequence(a.attrelid::regclass::text, a.attname) IS NOT NULL;