SELECT
A.ordinal_position,
A.column_name,
CASE A.is_nullable WHEN 'NO' THEN 0 ELSE 1 END AS is_nullable,
A.data_type,
coalesce(A.character_maximum_length, A.numeric_precision, -1) as length,
A.numeric_scale,
CASE WHEN length(B.attname) > 0 THEN 1 ELSE 0 END AS is_pk,E.comment
FROM
information_schema.columns A
LEFT JOIN (
SELECT
sys_attribute.attname
FROM
sys_index,
sys_class,
sys_attribute
WHERE
sys_class.oid = '表名' :: regclass
AND sys_index.indrelid = sys_class.oid
AND sys_attribute.attrelid = sys_class.oid
AND sys_attribute.attnum = ANY (sys_index.indkey)
) B ON A.column_name = b.attname
LEFT JOIN (
SELECT DISTINCT a.attname AS field, b.description AS comment
FROM sys_class c, sys_attribute a
LEFT JOIN sys_description b
ON (select min(oid) from sys_class where relname='表名') = b.objoid
AND a.attnum = b.objsubid, sys_type t
WHERE c.relname = '表名'
AND a.attnum > 0
AND a.attrelid = c.oid
AND a.atttypid = t.oid
) E ON E.field = A.column_name
WHERE
A.table_schema = '模式名'
AND A.table_name = '表名'
ORDER BY
ordinal_position ASC;
kingbase查看表的详细信息(字段、字段注释、长度、是否为主键、小数位数、是否为空)
最新推荐文章于 2024-06-24 16:10:53 发布