Re: How to retrieve Comment text using SQL, not psql?

From: Melvin Davidson <melvin6925(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Bob Futrelle <bob(dot)futrelle(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to retrieve Comment text using SQL, not psql?
Date: 2015-05-30 13:02:25
Message-ID: CANu8Fix5WH2m4w_VLve6ueHpriEBAZHTbd7mYcKn7o4mEfaSvw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

This will give the comment on your table and any column:

SELECT DISTINCT ON (c.relname)
n.nspname as schema,
c.relname,
a.rolname as owner,
0 as col_seq,
'' as column,
d.description as comment
FROM pg_class c
LEFT JOIN pg_attribute col ON (col.attrelid = c.oid)
LEFT JOIN pg_description d ON (d.objoid = col.attrelid AND d.objsubid = 0)
JOIN pg_namespace n ON (n.oid = c.relnamespace)
JOIN pg_authid a ON ( a.OID = c.relowner )
WHERE n.nspname NOT LIKE 'information%'
AND relname NOT LIKE 'pg_%'
AND relname NOT LIKE 'information%'
AND relname NOT LIKE 'sql_%'
AND relname = 'articlestats'
AND relkind = 'r'
AND d.description IS NOT NULL
UNION
SELECT n.nspname as schema,
c.relname,
'' as owner,
col.attnum as col_seq,
col.attname as column,
d.description
FROM pg_class c
JOIN pg_attribute col ON (col.attrelid = c.oid)
LEFT JOIN pg_description d ON (d.objoid = col.attrelid AND d.objsubid =
col.attnum)
JOIN pg_namespace n ON (n.oid = c.relnamespace)
JOIN pg_authid a ON ( a.OID = c.relowner )
WHERE n.nspname NOT LIKE 'information%'
AND relname NOT LIKE 'pg_%'
AND relname NOT LIKE 'information%'
AND relname NOT LIKE 'sql_%'
AND relname = 'articlestats'
AND relkind = 'r'
AND d.description IS NOT NULL
AND col.attnum >= 0
ORDER BY 1, 2, 4;

Learn the catalogs and you will learn PostgreSQL!

On Sat, May 30, 2015 at 7:58 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
wrote:

> Hi
>
> you can call function obj_description
> http://stackoverflow.com/questions/11493978/how-to-retrieve-the-comment-of-a-postgresql-database
>
> http://www.postgresql.org/docs/9.1/static/functions-info.html
>
> For tables
>
> SELECT pg_catalog.obj_description('tablename'::regclass, 'pg_class') as
> "Description;
>
> Regards
>
> Pavel Stehule
>
> 2015-05-30 13:48 GMT+02:00 Bob Futrelle <bob(dot)futrelle(at)gmail(dot)com>:
>
>> Using pgAdmin3 I've tried this and variations on it. All are rejected.
>>
>> select COMMENT ON TABLE articlestats
>>
>>
>> No answer here,
>>
>> http://www.postgresql.org/docs/9.3/static/sql-comment.html
>>
>>
>> pgAdmin3 had no problem with entering a comment:
>>
>> COMMENT ON TABLE articlestats IS 'Comprehensive data for every article.'
>>
>>
>> - Bob Futrelle
>>
>>
>

--
*Melvin Davidson*
I reserve the right to fantasize. Whether or not you
wish to share my fantasy is entirely up to you.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2015-05-30 13:37:21 Re: How to retrieve Comment text using SQL, not psql?
Previous Message Andreas Kretschmer 2015-05-30 12:10:05 Re: replacing jsonb field value