SQL to get a table columns comments?

Lists: pgsql-generalpgsql-hackers
From: "Timasmith" <timasmith(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org pgsql-hackers(at)postgresql(dot)org
Subject: SQL to get a table columns comments?
Date: 2007-01-28 01:57:06
Message-ID: 1169949426.721522.117610@a75g2000cwd.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers

Hi,

What query can I run to get the comments for my table columns.

i.e. the ones on my 8.1 database added with this command:

COMMENT ON COLUMN addresses.address_id IS 'Unique identifier for the
addresses table';

thanks

Tim


From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL to get a table columns comments?
Date: 2007-01-30 06:32:11
Message-ID: 20070130063211.GB12767@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers

am Sat, dem 27.01.2007, um 17:57:06 -0800 mailte Timasmith folgendes:
> Hi,
>
> What query can I run to get the comments for my table columns.
>
> i.e. the ones on my 8.1 database added with this command:
>
> COMMENT ON COLUMN addresses.address_id IS 'Unique identifier for the
> addresses table';

Start psql with Option -E and type '\d+ <tablename>'. (without the ')

Then you can see the underlaying SQL-Query to request this.

Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net


From: "codeWarrior" <gpatnude(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org(dot)pgsql-hackers(at)postgresql(dot)org
Subject: Re: SQL to get a table columns comments?
Date: 2007-01-30 17:15:11
Message-ID: epnu7t$1vbv$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers

SELECT
CASE
WHEN sfl.description IS NOT NULL THEN sfl.description
WHEN sfl.description IS NULL THEN pa.attname::character varying
ELSE pd.description::character varying
END AS label
FROM ONLY pg_class pc
JOIN ONLY pg_attribute pa ON pc.oid = pa.attrelid AND pc.relnamespace =
2200::oid AND pc.reltype > 0::oid AND (pc.relkind = 'r'::"char" OR
pc.relkind = 'c'::"char" OR pc.relkind = 'v'::"char")
JOIN ONLY pg_type pt ON pa.atttypid = pt.oid
LEFT JOIN ONLY pg_description pd ON pc.oid = pd.objoid AND pa.attnum =
pd.objsubid
LEFT JOIN sys_flex_labels sfl ON pc.oid = sfl.table_oid::oid AND
pa.attname::character varying::text = sfl.column_name::text
WHERE pa.attnum > 0
ORDER BY pc.relname::character varying, pa.attnum;

"Timasmith" <timasmith(at)hotmail(dot)com> wrote in message
news:1169949426(dot)721522(dot)117610(at)a75g2000cwd(dot)googlegroups(dot)com(dot)(dot)(dot)
> Hi,
>
> What query can I run to get the comments for my table columns.
>
> i.e. the ones on my 8.1 database added with this command:
>
> COMMENT ON COLUMN addresses.address_id IS 'Unique identifier for the
> addresses table';
>
> thanks
>
> Tim
>


From: "Timasmith" <timasmith(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL to get a table columns comments?
Date: 2007-01-30 20:17:19
Message-ID: 1170188239.402691.63170@v33g2000cwv.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers

On Jan 30, 12:15 pm, "codeWarrior" <gpatn(dot)(dot)(dot)(at)hotmail(dot)com> wrote:
> SELECT
> CASE
> WHEN sfl.description IS NOT NULL THEN sfl.description
> WHEN sfl.description IS NULL THEN pa.attname::character varying
> ELSE pd.description::character varying
> END AS label
> FROM ONLY pg_class pc
> JOIN ONLY pg_attribute pa ON pc.oid = pa.attrelid AND pc.relnamespace =
> 2200::oid AND pc.reltype > 0::oid AND (pc.relkind = 'r'::"char" OR
> pc.relkind = 'c'::"char" OR pc.relkind = 'v'::"char")
> JOIN ONLY pg_type pt ON pa.atttypid = pt.oid
> LEFT JOIN ONLY pg_description pd ON pc.oid = pd.objoid AND pa.attnum =
> pd.objsubid
> LEFT JOIN sys_flex_labels sfl ON pc.oid = sfl.table_oid::oid AND
> pa.attname::character varying::text = sfl.column_name::text
> WHERE pa.attnum > 0
> ORDER BY pc.relname::character varying, pa.attnum;
>
> "Timasmith" <timasm(dot)(dot)(dot)(at)hotmail(dot)com> wrote in message
>
> news:1169949426(dot)721522(dot)117610(at)a75g2000cwd(dot)googlegroups(dot)com(dot)(dot)(dot)
>
>
>
> > Hi,
>
> > What query can I run to get the comments for my table columns.
>
> > i.e. the ones on my 8.1 database added with this command:
>
> > COMMENT ON COLUMN addresses.address_id IS 'Unique identifier for the
> > addresses table';
>
> > thanks
>
> > Tim- Hide quoted text -
>
> - Show quoted text -

I dont know about that query - I dont have sys_flex_labels but this
seems to work:

select pc.relname as tablename, pa.attname as column, pd.description
from pg_description pd, pg_class pc, pg_attribute pa
where pc.relowner = 16403
and pa.attrelid = pc.oid
and pd.objoid = pc.oid
and pd.objsubid = pa.attnum

where I had to figure out the relowner and my schema owner


From: Jim Nasby <decibel(at)decibel(dot)org>
To: Timasmith <timasmith(at)hotmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL to get a table columns comments?
Date: 2007-02-02 03:46:48
Message-ID: F8691649-3414-48F9-A0EF-F4828100790E@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general pgsql-hackers

On Jan 27, 2007, at 8:57 PM, Timasmith wrote:
> What query can I run to get the comments for my table columns.
>
> i.e. the ones on my 8.1 database added with this command:
>
> COMMENT ON COLUMN addresses.address_id IS 'Unique identifier for the
> addresses table';

There's a function that allows you to do that; see the 'System
Information Functions' section of the docs.
--
Jim Nasby jim(at)nasby(dot)net
EnterpriseDB http://enterprisedb.com 512.569.9461 (cell)