PostgreSQL:使用不带斜杠语法的 SQL 显示域属性
PostgreSQL: Showing domain properties using SQL without the Slash Syntax
在 PostgreSQL 中,显示域的属性是使用 \dD
完成的,例如:
\dD dom_reason
List of domains
Schema | Name | Type | Modifier | Check
....
在 DataGrip 中,\
notation is not yet supported。有没有一种方法可以直接使用 SQL?
查询域属性
像这样:
SELECT n.nspname as domain_schema,
t.typname as domain_name,
pg_catalog.format_type(t.typbasetype, t.typtypmod) as data_type,
not t.typnotnull as nullable,
t.typdefault as default_value,
c.conname as constraint_name,
pg_catalog.pg_get_constraintdef(c.oid, true) as constraint_definition,
obj_description(t.oid) as remarks
FROM pg_catalog.pg_type t
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
LEFT JOIN pg_catalog.pg_constraint c ON t.oid = c.contypid
WHERE t.typtype = 'd'
AND n.nspname = 'public' -- change here for your schema name
通过使用选项 -E
或 --echo-hidden
启动 psql,您可以轻松找到 psql
用于其每个反斜杠命令的语句
在 PostgreSQL 中,显示域的属性是使用 \dD
完成的,例如:
\dD dom_reason
List of domains
Schema | Name | Type | Modifier | Check
....
在 DataGrip 中,\
notation is not yet supported。有没有一种方法可以直接使用 SQL?
像这样:
SELECT n.nspname as domain_schema,
t.typname as domain_name,
pg_catalog.format_type(t.typbasetype, t.typtypmod) as data_type,
not t.typnotnull as nullable,
t.typdefault as default_value,
c.conname as constraint_name,
pg_catalog.pg_get_constraintdef(c.oid, true) as constraint_definition,
obj_description(t.oid) as remarks
FROM pg_catalog.pg_type t
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
LEFT JOIN pg_catalog.pg_constraint c ON t.oid = c.contypid
WHERE t.typtype = 'd'
AND n.nspname = 'public' -- change here for your schema name
通过使用选项 -E
或 --echo-hidden
psql
用于其每个反斜杠命令的语句