如何在 PostgreSQL 中获取表的列表列名和数据类型? [英] How to get a list column names and datatypes of a table in PostgreSQL?

查看:85
本文介绍了如何在 PostgreSQL 中获取表的列表列名和数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用查询获取 PostgreSQL 中表的列名和数据类型列表?

How can I get a list of column names and datatypes of a table in PostgreSQL using a query?

推荐答案

SELECT
        a.attname as "Column",
        pg_catalog.format_type(a.atttypid, a.atttypmod) as "Datatype"
    FROM
        pg_catalog.pg_attribute a
    WHERE
        a.attnum > 0
        AND NOT a.attisdropped
        AND a.attrelid = (
            SELECT c.oid
            FROM pg_catalog.pg_class c
                LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
            WHERE c.relname ~ '^(hello world)$'
                AND pg_catalog.pg_table_is_visible(c.oid)
        );

更多信息:http://www.postgresql.org/docs/9.3/static/catalog-pg-attribute.html

这篇关于如何在 PostgreSQL 中获取表的列表列名和数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆