要使用information_schema查詢PostgreSQL數據庫信息,可以使用以下SQL語句:
SELECT datname
FROM information_schema.schemata;
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public';
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'table_name';
SELECT column_name
FROM information_schema.key_column_usage
WHERE table_name = 'table_name'
AND constraint_name = 'PRIMARY';
SELECT constraint_name, column_name, referenced_table_name, referenced_column_name
FROM information_schema.key_column_usage
WHERE table_name = 'table_name'
AND constraint_name != 'PRIMARY';
這些是使用information_schema查詢PostgreSQL數據庫信息的一些常用示例,根據具體需求可以靈活運用。