Postgresql 查询数据库列表,表列表,字段列表

-- 列出数据库列表
SELECT * FROM pg_database;

-- 查询表字段明细
SELECT
	col.table_schema,
	col.table_name,
	col.ordinal_position,
	col.column_name,
	col.data_type,
	col.character_maximum_length,
	col.numeric_precision,
	col.numeric_scale,
	col.is_nullable,
	col.column_default,
	des.description 
FROM
	information_schema.COLUMNS col
	LEFT JOIN pg_description des ON col.table_name :: regclass = des.objoid 
	AND col.ordinal_position = des.objsubid 
WHERE
	table_name = 'test' 
ORDER BY
	ordinal_position;

-- 查询有哪些表
SELECT *
FROM pg_catalog.pg_tables
WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema';


-- 当前连接的数据库中的所有表
SELECT tablename
FROM pg_tables
WHERE schemaname = current_schema();

你可能感兴趣的:(postgresql,数据库)