PostgreSQL獲取table名,字段名


PostgreSQL獲取數據庫中所有table名:

SELECT tablename
FROM pg_tables
WHERE tablename NOT LIKE 'pg%'
      AND tablename NOT LIKE 'sql_%'
ORDER BY  tablename;

 

PostgreSQL獲取數據庫中所有table名及table的注解信息:

SELECT tablename,
        obj_description(relfilenode,
        'pg_class')
FROM pg_tables a, pg_class b
WHERE a.tablename = b.relname
        AND a.tablename NOT LIKE 'pg%'
        AND a.tablename NOT LIKE 'sql_%'
ORDER BY  a.tablename;

PostgreSQL獲取指定table的所有字段信息:

SELECT col_description(a.attrelid,
        a.attnum) AS comment,
        format_type(a.atttypid,
        a.atttypmod) AS type,
        a.attname AS name,
         a.attnotnull AS notnull
FROM pg_class AS c,pg_attribute AS a
WHERE c.relname = 'tablename'
        AND a.attrelid = c.oid
        AND a.attnum>0

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM