如何获得正确的列类型名称?

How to get the right colum type name?

我需要知道 table 的列类型名称,目前我正在使用此查询:

SELECT column_name as name,
        data_type as type
FROM information_schema.columns
WHERE table_name = 'MY_TABLE';

问题在于,对于像 geometry (POSTGIS) 这样的数据类型,它是 returns USER-DEFINED 而不是 geometry

有没有办法获得正确的列类型名称?

我现在不能测试这个,但是根据 documentation for information_schema.columns:

data_type

Data type of the column, if it is a built-in type, or ARRAY if it is some array (in that case, see the view element_types), else USER-DEFINED (in that case, the type is identified in udt_name and associated columns). If the column is based on a domain, this column refers to the type underlying the domain (and the domain is identified in domain_name and associated columns).

因此,udt_name 列可能包含您想要的内容。