Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database Postgresql列来自模式的信息,包括说明_Database_Postgresql_Schema - Fatal编程技术网

Database Postgresql列来自模式的信息,包括说明

Database Postgresql列来自模式的信息,包括说明,database,postgresql,schema,Database,Postgresql,Schema,我需要从数据库中的所有表连接一些列信息,我找到了这个选择 SELECT 'postgresql' AS dbms, t.table_catalog,t.table_schema, t.table_name,c.column_name, c.ordinal_position,c.data_type, c.character_maximum_length, n.constraint_type, k2.ta

我需要从数据库中的所有表连接一些列信息,我找到了这个选择

SELECT 'postgresql' AS dbms,
        t.table_catalog,t.table_schema,
        t.table_name,c.column_name,
        c.ordinal_position,c.data_type,
        c.character_maximum_length,
        n.constraint_type,
        k2.table_schema,
        k2.table_name,
        k2.column_name

FROM information_schema.tables t 
    NATURAL LEFT JOIN information_schema.columns c 
        LEFT JOIN(
            information_schema.key_column_usage k 
                NATURAL JOIN information_schema.table_constraints n 
                NATURAL LEFT JOIN information_schema.referential_constraints r) 
        ON c.table_catalog=k.table_catalog 
        AND c.table_schema=k.table_schema 
        AND c.table_name=k.table_name 
        AND c.column_name=k.column_name 
    LEFT JOIN information_schema.key_column_usage k2 
        ON k.position_in_unique_constraint=k2.ordinal_position 
        AND r.unique_constraint_catalog=k2.constraint_catalog 
        AND r.unique_constraint_schema=k2.constraint_schema 
        AND r.unique_constraint_name=k2.constraint_name 
WHERE t.TABLE_TYPE='BASE TABLE' AND t.table_schema NOT IN('information_schema','pg_catalog')
ORDER BY t.table_name;
这个查询提供了很多信息,但我需要所有列名称的描述

我找到了另一个显示描述的查询

SELECT *

FROM pg_catalog.pg_statio_all_tables as st
        inner join pg_catalog.pg_description pgd on (pgd.objoid=st.relid)
        inner join information_schema.columns c on (pgd.objsubid=c.ordinal_position
                and  c.table_schema=st.schemaname and c.table_name=st.relname);
问题是如何将第二个查询中的字段pgd.description插入第一个查询中

谢谢和问候
Curro

它们是两组不同的元数据功能:第一组使用通用信息模式,而第二组使用PostgreSQL的特定系统功能。可以通过从模式中获取对象id(oid)和从信息\u模式表中获取表名来连接它们:

SELECT 'postgresql' AS dbms,
        t.table_catalog,t.table_schema,
        t.table_name,c.column_name,
        c.ordinal_position,c.data_type,
        c.character_maximum_length,
        n.constraint_type,
        k2.table_schema,
        k2.table_name,
        k2.column_name,
        td.description AS table_description,
        cd.description AS column_description
FROM information_schema.tables t
    LEFT JOIN pg_catalog.pg_description td
        ON (td.objoid = (quote_ident(t.table_schema)||'.'||quote_ident(t.table_name))::regclass AND td.objsubid = 0)
    NATURAL LEFT JOIN information_schema.columns c 
        LEFT JOIN(
            information_schema.key_column_usage k 
                NATURAL JOIN information_schema.table_constraints n 
                NATURAL LEFT JOIN information_schema.referential_constraints r) 
        ON c.table_catalog=k.table_catalog 
        AND c.table_schema=k.table_schema 
        AND c.table_name=k.table_name 
        AND c.column_name=k.column_name 
    LEFT JOIN information_schema.key_column_usage k2 
        ON k.position_in_unique_constraint=k2.ordinal_position 
        AND r.unique_constraint_catalog=k2.constraint_catalog 
        AND r.unique_constraint_schema=k2.constraint_schema 
        AND r.unique_constraint_name=k2.constraint_name 
    LEFT JOIN pg_catalog.pg_description cd
        ON (cd.objoid = (quote_ident(t.table_schema)||'.'||quote_ident(t.table_name))::regclass AND cd.objsubid = c.ordinal_position)
WHERE t.TABLE_TYPE='BASE TABLE' AND t.table_schema NOT IN('information_schema','pg_catalog')
ORDER BY t.table_name;

它们是两组不同的元数据函数:第一组使用universal information_模式,而第二组使用PostgreSQL的特定系统函数。可以通过从模式中获取对象id(oid)和从信息\u模式表中获取表名来连接它们:

SELECT 'postgresql' AS dbms,
        t.table_catalog,t.table_schema,
        t.table_name,c.column_name,
        c.ordinal_position,c.data_type,
        c.character_maximum_length,
        n.constraint_type,
        k2.table_schema,
        k2.table_name,
        k2.column_name,
        td.description AS table_description,
        cd.description AS column_description
FROM information_schema.tables t
    LEFT JOIN pg_catalog.pg_description td
        ON (td.objoid = (quote_ident(t.table_schema)||'.'||quote_ident(t.table_name))::regclass AND td.objsubid = 0)
    NATURAL LEFT JOIN information_schema.columns c 
        LEFT JOIN(
            information_schema.key_column_usage k 
                NATURAL JOIN information_schema.table_constraints n 
                NATURAL LEFT JOIN information_schema.referential_constraints r) 
        ON c.table_catalog=k.table_catalog 
        AND c.table_schema=k.table_schema 
        AND c.table_name=k.table_name 
        AND c.column_name=k.column_name 
    LEFT JOIN information_schema.key_column_usage k2 
        ON k.position_in_unique_constraint=k2.ordinal_position 
        AND r.unique_constraint_catalog=k2.constraint_catalog 
        AND r.unique_constraint_schema=k2.constraint_schema 
        AND r.unique_constraint_name=k2.constraint_name 
    LEFT JOIN pg_catalog.pg_description cd
        ON (cd.objoid = (quote_ident(t.table_schema)||'.'||quote_ident(t.table_name))::regclass AND cd.objsubid = c.ordinal_position)
WHERE t.TABLE_TYPE='BASE TABLE' AND t.table_schema NOT IN('information_schema','pg_catalog')
ORDER BY t.table_name;