• 周六. 10月 8th, 2022

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

PostgreSQL获取表名和字段名

admin

11月 28, 2021
-- 获取所有table名
SELECT
	tablename
FROM
	pg_tables
WHERE
	tablename NOT LIKE 'pg%'
AND tablename NOT LIKE 'sql_%'
AND schemaname = 'public'
ORDER BY
	tablename;

--获取pg库中所有table名以及table的注解信息 
SELECT
	tablename,
	obj_description (relfilenode, 'pg_class')
FROM
	pg_tables A,
	pg_class b
WHERE
	A .tablename = b.relname
AND A .schemaname = 'public'
AND A .tablename NOT LIKE 'pg%'
AND A .tablename NOT LIKE 'sql_%';

SELECT * FROM pg_attribute
--pg获取制定table的所有字段信息 
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 = 'yuhang_road'--指定表
AND A .attrelid = C .oid
AND A .attnum > 0;

  

发表回复

您的电子邮箱地址不会被公开。