Postgresql 查询表的字段信息,字段名,类型,注释等

Postgresql 查询表的字段信息,字段名,类型,注释,是否为空

SELECT
	col_description ( A.attrelid, A.attnum ) AS COMMENT,
	format_type ( A.atttypid, A.atttypmod ) AS TYPE,
	A.attname AS NAME,
	A.attnotnull AS NOTNULL
FROM
	pg_class AS C,
	pg_attribute AS A 
WHERE
	C.relname = 'sys_user' 
	AND A.attrelid = C.oid 
	AND A.attnum > 0

查询所有表名和注释

SELECT
	relname AS tabname,
	CAST ( obj_description ( relfilenode, 'pg_class' ) AS VARCHAR ) AS COMMENT
FROM
	pg_class C 
WHERE
	relkind = 'r' 
	AND relname NOT LIKE'pg_%' 
	AND relname NOT LIKE'sql_%' 
ORDER BY
	relname

你可能感兴趣的:(Postgresql)