dbTalk Databases Forums  

Re: How can I select a comment on a column in a query?

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Re: How can I select a comment on a column in a query? in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
George Weaver
 
Posts: n/a

Default Re: How can I select a comment on a column in a query? - 01-19-2004 , 09:41 AM






Hi Roman,

Comments are stored in the system catalog table pg_description. To select a
column comment ("description" in pg_description) you need the specify the
objoid for the table ("relfilenode" from pg_class for the table in question)
and the column number ("objsubid").

test=# select description from pg_description where objoid = 306461 and
objsubid = 0;

description
-----------------------------------
Weight Units~Unit~unitdescription
(1 row)

HTH,
George

----- Original Message -----
From: "A u r k a" <aurka (AT) centrum (DOT) cz>
To: <pgsql-novice (AT) postgresql (DOT) org>
Sent: Thursday, January 15, 2004 9:04 AM
Subject: [NOVICE] How can I select a comment on a column in a query?


Quote:
Hello,

I have been going through the manuals for couple of hours looking for a
way to select a comment on a column in a query. Can it be done (and used
with php)?

Thanks for any advice

Roman Dergam


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


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend



Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: How can I select a comment on a column in a query? - 01-19-2004 , 09:54 AM






George Weaver <gweaver (AT) shaw (DOT) ca> writes:
Quote:
test=# select description from pg_description where objoid = 306461 and
objsubid = 0;
Also, there is a col_description() function that encapsulates this
query. I'd recommend col_description() and its sibling obj_description()
in preference to examining the pg_description catalog directly. See
"Comment Information Functions" in
http://www.postgresql.org/docs/7.4/s...ions-misc.html

Here's a simple example:

regression=# create table mytab (mycol int);
CREATE TABLE
regression=# comment on column mytab.mycol is 'my comment';
COMMENT
regression=# select col_description('mytab'::regclass, 1);
col_description
-----------------
my comment
(1 row)

(I'm using the regclass datatype as a substitute for an explicit
lookup in pg_class to get the OID of the table. This feature is
new since 7.3 or thereabouts.)

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo (AT) postgresql (DOT) org



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.