Re: [SQL] System Attribute

Lists: pgsql-sql
From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Steven M(dot) Wheeler" <swheeler(at)sabre(dot)com>
Cc: pgsql-sql(at)hub(dot)org
Subject: Re: [SQL] How do I get column names?
Date: 1999-12-13 22:50:47
Message-ID: 12856.945125447@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

"Steven M. Wheeler" <swheeler(at)sabre(dot)com> writes:
> What is the best way to query the DB, to get the column names for a
> particular table?

Usually you'd join across pg_attribute and pg_class, assuming that you
were starting from a table name. For example:

regression=> select attname, attnum from pg_attribute, pg_class where
regression-> attrelid = pg_class.oid and relname = 'int8_tbl';
attname|attnum
-------+------
cmax | -6
xmax | -5
cmin | -4
xmin | -3
oid | -2
ctid | -1
q1 | 1
q2 | 2
(8 rows)

You probably would also want 'and attnum > 0' in the where-clause to
exclude the system attributes...

regards, tom lane


From: Drew Whittle <drew(at)albatross(dot)co(dot)nz>
To: pgsql-sql(at)hub(dot)org
Subject: System Attribute
Date: 1999-12-14 00:14:14
Message-ID: 4.2.0.58.19991214131113.00c5dad0@pern.csarc.otago.ac.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

We have an online order system that I am trying to convert to use postgres
and I noticed a problem with the creation of the DB.

One of the tables has a field called 'oid', which is fine under lots of
other DB's but postgres doesn't like it. I am in the process of renaming
this field so things will work but I am curious what the error actually means:

ERROR: create: system attribute named "oid"

Thanks,

Drew


From: Mathijs Brands <mathijs(at)ilse(dot)nl>
To: Drew Whittle <drew(at)albatross(dot)co(dot)nz>
Cc: pgsql-sql(at)hub(dot)org
Subject: Re: [SQL] System Attribute
Date: 1999-12-14 00:33:51
Message-ID: 19991214013351.A11540@ilse.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-sql

On Tue, Dec 14, 1999 at 01:14:14PM +1300, Drew Whittle allegedly wrote:
> We have an online order system that I am trying to convert to use postgres
> and I noticed a problem with the creation of the DB.
>
> One of the tables has a field called 'oid', which is fine under lots of
> other DB's but postgres doesn't like it. I am in the process of renaming
> this field so things will work but I am curious what the error actually means:
>
> ERROR: create: system attribute named "oid"
>
> Thanks,
>
> Drew

Every record in a table has a unique OID value. So if you were to insert the
same value twice, you would be able to keep them apart using the OID value.
Since PostgreSQL uses the oid field internally, you cannot use it.

I hope this helps.

Mathijs