forked from andyatkinson/pg_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_comments.sql
More file actions
33 lines (30 loc) · 848 Bytes
/
list_comments.sql
File metadata and controls
33 lines (30 loc) · 848 Bytes
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
30
31
32
33
-- https://stackoverflow.com/questions/343138/retrieving-comments-from-a-postgresql-db
select
c.table_schema,
st.relname as TableName,
c.column_name,
pgd.description
from pg_catalog.pg_statio_all_tables as st
inner join information_schema.columns c
on c.table_schema = st.schemaname
and c.table_name = st.relname
left join pg_catalog.pg_description pgd
on pgd.objoid=st.relid
and pgd.objsubid=c.ordinal_position
where st.relname = 'YourTableName';
-- https://stackoverflow.com/a/4946306
SELECT
c.table_schema,
c.table_name,
c.column_name,
pgd.description
FROM
pg_catalog.pg_statio_all_tables AS st
INNER JOIN
pg_catalog.pg_description pgd
ON ( pgd.objoid = st.relid )
INNER JOIN
information_schema.columns c
ON ( pgd.objsubid = c.ordinal_position
AND c.table_schema = st.schemaname
AND c.table_name = st.relname );