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

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

问题描述

通过以下查询,我们可以获得PostgreSQL中表的列名和数据类型的列表。

With the following query, we can get a list of column names and datatype of a table in PostgreSQL.

推荐答案

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天全站免登陆