在PostgreSQL,请查询系统数据表。
你还可以询问Schema的信息,该信息包括提供显示信息的标准方式的意见。 记录系统数据集通常要更快得多,尽管如此。
寻找一个特定孩子:<代码>/代码>。 页: 1
SELECT n.nspname AS schema_name
, c.relname AS table_name
, a.attname AS column_name
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON c.oid = a.attrelid
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE a.attname ~~ E %\_parent
AND NOT a.attisdropped
AND c.relkind = r
AND nspname !~~ E pg\_% ;
根据说明查找<>all相关栏目:
SELECT n.nspname AS parrent_schema
, c.relname AS parrent_table
, a.attname AS parrent_column
, n1.nspname AS child_schema
, c1.relname AS child_table
, a1.attname AS child_column
FROM pg_catalog.pg_attribute a
JOIN pg_catalog.pg_class c ON c.oid = a.attrelid
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
JOIN pg_catalog.pg_attribute a1 ON a.attname = substring(a1.attname, _(.*?)$ )
JOIN pg_catalog.pg_class c1 ON c1.oid = a1.attrelid
JOIN pg_catalog.pg_namespace n1 ON n1.oid = c1.relnamespace
WHERE c.relkind = r
AND c1.relkind = r
AND n.nspname !~~ E pg\_%
AND n1.nspname !~~ E pg\_%
AND NOT a.attisdropped
AND NOT a1.attisdropped
-- AND n.nspname = public -- to narrow it down to a specific schema
-- AND n1.nspname = public -- to narrow it down to a specific schema
ORDER BY 1,2,3,4,5,6
This assumes that the parrent columns don t have _
in the name.
The key element is the join condition:
a.attname = substring(a1.attname, _(.*?)$ )