postgresql 获取表注释

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
SELECT
 
string_agg(DISTINCT t3.attname,',') AS primaryKeyColumn
 
,t4.tablename AS tableName
 
, string_agg(cast(obj_description(relfilenode,'pg_class') as varchar),'') as comment
 
FROM
 
pg_constraint t1
 
INNER JOIN pg_class t2 ON t1.conrelid = t2.oid
 
INNER JOIN pg_attribute t3 ON t3.attrelid = t2.oid AND array_position(t1.conkey,t3.attnum) is not null
 
INNER JOIN pg_tables t4 on t4.tablename = t2.relname
 
INNER JOIN pg_index t5 ON t5.indrelid = t2.oid AND t3.attnum = ANY (t5.indkey)
 
LEFT JOIN pg_description t6 on t6.objoid=t3.attrelid and t6.objsubid=t3.attnum
 
WHERE t1.contype = 'p'
 
AND length(t3.attname) > 0
 
AND t2.oid = '表名' :: regclass
 
group by t4.tablename

  

posted @   qukaige  阅读(294)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示