--表pg_class 列pg_attribute 类型pg_type 约束 pg_constraint
--查询主键约束
select conname,conkey,conrelid from pg_constraint;
--将主键约束数组分解为结果集
select conname,unnest(conkey),conrelid from pg_constraint;
--获取public名下所有表
SELECT tablename FROM pg_tables where schemaname='public';
select b.relname as table_name,a.attname as column_name,a.attnotnull as not_null,c.typname as type_name,d.pk from pg_attribute a
left join pg_class b on a.attrelid = b.oid
left join pg_type c on a.atttypid= c.oid
left join (select conname,unnest(conkey) pk,conrelid from pg_constraint) d on d.conrelid =b.oid and attnum=pk
where relname in (SELECT tablename FROM pg_tables where schemaname='public')
and attnum >0
order by relname,attnum;
Postgresql 逆向工程的SQL文
最新推荐文章于 2024-03-24 15:03:05 发布