information_schema.columns返回不同的数据类型。

时间:2015-07-10 05:03:49

标签: postgresql information-schema

在胶片表内的pagila示例数据库中有一个名为release_year的列,数据类型为year,但是当我使用information_schema查询此列数据类型时,我得到Integer,因为它的数据类型出了什么问题?我用过的查询

select c.column_name,c.data_type
from information_schema.columns c
where c.table_name = 'film'
;

如何获取实际数据类型?

1 个答案:

答案 0 :(得分:1)

我使用此查询得到了答案:

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 ~ '^(table_name)$'
            AND pg_catalog.pg_table_is_visible(c.oid)
    )
;

enter code here