How to retrieve a comment/description from a table

Started by Marcus Claessonover 23 years ago6 messagesgeneral
Jump to latest
#1Marcus Claesson
marcus.claesson@angiogenetics.se

Hello!
This psql command is very straight forward and promising:
COMMENT ON mytable IS 'This is my table.';

But how can I retrieve the particular comment from that table again?
Using \d+ gives you all the tables with their comments. I want a special
one.

And if that is not possible, can the \d+ results be obtained from a
system table or so?

Thanks,
Marcus

#2Darren Ferguson
darren@crystalballinc.com
In reply to: Marcus Claesson (#1)
Re: How to retrieve a comment/description from a table

\d+ mytable will give you the comments for it

For system tables just do

\d+ pg_** substitute ** for system table name

HTH
On Fri, 23 Aug 2002, Marcus Claesson wrote:

Hello!
This psql command is very straight forward and promising:
COMMENT ON mytable IS 'This is my table.';

But how can I retrieve the particular comment from that table again?
Using \d+ gives you all the tables with their comments. I want a special
one.

And if that is not possible, can the \d+ results be obtained from a
system table or so?

Thanks,
Marcus

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

--
Darren Ferguson

#3Marcus Claesson
marcus.claesson@angiogenetics.se
In reply to: Darren Ferguson (#2)
Re: How to retrieve a comment/description from a table

\d+ mytable will give you the comments for it

This only gives me the same information as if I wrote '\d mytable', plus an
empty description column. I couldn't see my comment anywhere.

What I wish is to retrieve the comment with a sql question, which would work
if the '\d+ information' could be found in an actual table somewhere.

Regards,
Marcus

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Marcus Claesson (#3)
Re: How to retrieve a comment/description from a table

Marcus Claesson <marcus.claesson@angiogenetics.se> writes:

What I wish is to retrieve the comment with a sql question, which would work
if the '\d+ information' could be found in an actual table somewhere.

The descriptions are kept in pg_description. Although you can just do
"select from pg_description", the recommended retrieval method is the
obj_description() function. See
http://www.ca.postgresql.org/users-lounge/docs/7.2/postgres/functions-misc.html
http://www.ca.postgresql.org/users-lounge/docs/7.2/postgres/catalog-pg-description.html

regards, tom lane

#5Peter Gibbs
peter@emkel.co.za
In reply to: Darren Ferguson (#2)
Re: How to retrieve a comment/description from a table

Marcus Claesson wrote:

What I wish is to retrieve the comment with a sql question, which would

work

if the '\d+ information' could be found in an actual table somewhere.

select obj_description(oid, 'pg_class')
from pg_class
where relname = 'tablename';
--
Peter Gibbs
EmKel Systems

#6Stephan Szabo
sszabo@megazone23.bigpanda.com
In reply to: Marcus Claesson (#3)
Re: How to retrieve a comment/description from a table

On Fri, 23 Aug 2002, Marcus Claesson wrote:

\d+ mytable will give you the comments for it

This only gives me the same information as if I wrote '\d mytable', plus an
empty description column. I couldn't see my comment anywhere.

What I wish is to retrieve the comment with a sql question, which would work
if the '\d+ information' could be found in an actual table somewhere.

If you start psql with -E it will show you the queries it's running for
those backslash commands.

I believe \d+ table gives you column descriptions in that description
column.