PostgreSQL:如何列出所有可用的数据类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16343285/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PostgreSQL: How to list all available datatypes?
提问by Stefan Steiger
Question:
问题:
In PostgreSQL (using SQL, not the console), how can I list all available datataypes ?
在 PostgreSQL(使用 SQL,而不是控制台)中,如何列出所有可用的数据类型?
Ideally like this: http://www.java2s.com/Code/PostgreSQL/Postgre-SQL/Displaysalldatatypesintheconnecteddatabasewithcomments.htm
理想情况下是这样的:http: //www.java2s.com/Code/PostgreSQL/Postgre-SQL/Displaysalldatatypesintheconnecteddatabasewithcomments.htm
It should also list user defined types, if there are any.
Just like the list in pgAdmin3 where you define the datatype for a new column in a table.
如果有的话,它还应该列出用户定义的类型。
就像 pgAdmin3 中的列表一样,您可以在其中为表中的新列定义数据类型。
回答by Craig Ringer
"data types" in PostgreSQL actually includes primitive (built-in) types, types added by extensions, user-defined composite types, domains, and table rowtypes. It isn't clear which of these are of interest to you. All types available in a given database are listed in that database's pg_catalog.pg_type
so you may need to filter the results. See the documentation for the pg_type
system catalog table.
PostgreSQL 中的“数据类型”实际上包括原始(内置)类型、扩展添加的类型、用户定义的复合类型、域和表行类型。目前尚不清楚您对其中哪些感兴趣。给定数据库中可用的所有类型都列在该数据库中,pg_catalog.pg_type
因此您可能需要过滤结果。请参阅系统目录表的文档pg_type
。
Types for available but not installed extensions are notlisted. There's no way to list types provided by extensions not installed in the current database.
未列出可用但未安装的扩展的类型。无法列出当前数据库中未安装的扩展所提供的类型。
To get a prettier listing of types use psql
's \dT *
command. You can see the underlying SQL this executes by running psql
with the -E
flag:
要获得更漂亮的类型列表,请使用psql
's\dT *
命令。您可以通过psql
使用以下-E
标志运行来查看执行的底层 SQL :
$ psql -E regress
regress=> \dT *
********* QUERY **********
SELECT n.nspname as "Schema",
pg_catalog.format_type(t.oid, NULL) AS "Name",
pg_catalog.obj_description(t.oid, 'pg_type') as "Description"
FROM pg_catalog.pg_type t
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
WHERE (t.typrelid = 0 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid))
AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)
AND pg_catalog.pg_type_is_visible(t.oid)
ORDER BY 1, 2;
**************************