Discussion:
How to retrieve a comment/description from a table
Marcus Claesson
2002-08-23 14:22:25 UTC
Permalink
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 ***@postgresql.org)
Darren Ferguson
2002-08-23 14:28:44 UTC
Permalink
\d+ mytable will give you the comments for it

For system tables just do

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

HTH
Post by Marcus Claesson
Hello!
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
--
Darren Ferguson


---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Marcus Claesson
2002-08-23 15:00:03 UTC
Permalink
Post by Darren Ferguson
\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


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ***@postgresql.org so that your
message can get through to the mailing list cleanly
Tom Lane
2002-08-23 15:22:33 UTC
Permalink
Post by Marcus Claesson
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

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ***@postgresql.org so that your
message can get through to the mailing list cleanly
Peter Gibbs
2002-08-23 15:23:17 UTC
Permalink
Post by Marcus Claesson
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



---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Stephan Szabo
2002-08-23 15:37:16 UTC
Permalink
Post by Marcus Claesson
Post by Darren Ferguson
\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.


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ***@postgresql.org
Continue reading on narkive:
Loading...