要使用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数据库信息的一些常用示例,根据具体需求可以灵活运用。