Postgresql 使用默认sql表查找表中的列
我有一个postgresql数据库,其中包含按模式分割的客户端数据 在sql中,我想为表产品标识哪些列包含字符串“id” 我正在试着使用pg_uu3;。。。表来标识这些列,但下面的查询似乎在跨模式返回结果,尽管对表\u模式有限制Postgresql 使用默认sql表查找表中的列,postgresql,Postgresql,我有一个postgresql数据库,其中包含按模式分割的客户端数据 在sql中,我想为表产品标识哪些列包含字符串“id” 我正在试着使用pg_uu3;。。。表来标识这些列,但下面的查询似乎在跨模式返回结果,尽管对表\u模式有限制 SELECT * FROM pg_class c INNER JOIN pg_attribute a ON a.attrelid = c.oid INNER JOIN pg_type t ON a.atttypid = t.oid INNER JOIN in
SELECT *
FROM pg_class c
INNER JOIN pg_attribute a ON a.attrelid = c.oid
INNER JOIN pg_type t ON a.atttypid = t.oid
INNER JOIN information_schema.tables sch ON c.relname = sch.table_name
WHERE c.relname = 'products'
AND a.attnum > 0
AND a.attname LIKE '%id%'
AND table_schema = 'schema001'
我猜模式可能设置不正确,或者where子句不正确-如果有任何帮助,请使用pg_名称空间并删除信息_模式:
SELECT nspname, relname, attname
FROM pg_class c
INNER JOIN pg_namespace n ON n.oid = c.relnamespace
INNER JOIN pg_attribute a ON a.attrelid = c.oid
INNER JOIN pg_type t ON a.atttypid = t.oid
WHERE c.relname = 'products'
AND a.attnum > 0
AND a.attname LIKE '%id%'
AND n.nspname = 'schema001';
谢谢你真是太棒了!你知道我在哪里可以找到关于这些表格的文档吗?由于它们非常方便,但难以解释,因此它们是系统目录的一部分: