Home > Archive > PostgreSQL Discussion > September 2005 > [SQL] add column if doesn't exist (fwd)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author [SQL] add column if doesn't exist (fwd)
Brandon Metcalf

2005-09-26, 8:24 pm

I figured pgsql-general would be a more appropriate forum for the
question below.

--
Brandon

---------- Forwarded message ----------
Date: Mon, 26 Sep 2005 15:38:56 -0500 (CDT)
From: "Metcalf, Brandon & #91;SC100:CM21:EXCH]
" < bmetcalf@americasm01
.nt.com>
To: pgsql-sql@postgresql.org
Subject: [SQL] add column if doesn't exist

Is there a way to check for the existence of a column in a table other
than, say, doing a SELECT on that column name and checking the output?

I'm basically looking to do an ALTER TABLE foo ADD COLUMN bar if bar
doesn't exist.

Thanks.

--
Brandon

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Qingqing Zhou

2005-09-26, 8:24 pm


""Brandon Metcalf"" <bmetcalf@nortel.com> wrote

>
> Is there a way to check for the existence of a column in a table other
> than, say, doing a SELECT on that column name and checking the output?
>


Take a look at pg_attribute system table.
http://www.postgresql.org/docs/8.0/...-attribute.html

Regards,
Qingqing


Jim C. Nasby

2005-09-29, 8:23 pm

On Mon, Sep 26, 2005 at 07:16:53PM -0700, Qingqing Zhou wrote:
>
> ""Brandon Metcalf"" <bmetcalf@nortel.com> wrote
>
> Take a look at pg_attribute system table.
> http://www.postgresql.org/docs/8.0/...-attribute.html


You might find the information_schema or pg_newsysviews
(http://pgfoundry.org/projects/newsysviews/) easier to use.
--
Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

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

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com