Re: add column if doesn't exist

From: "Brandon Metcalf" <bmetcalf(at)nortel(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: add column if doesn't exist
Date: 2005-09-27 12:45:59
Message-ID: Pine.LNX.4.58L.0509270732170.1453@cash.rhiamet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

p == peter_e(at)gmx(dot)net writes:

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

p> SELECT * FROM information_schema.columns;

p> Customize to taste.

Yes, that's what I'm looking for. Thanks.

Now, is there a way to mix PostgreSQL commands and SQL and do
something like

ALTER TABLE foo ADD COLUMN bar WHERE EXISTS(SELECT * FROM
information_schema.columns WHERE ...)

?

--
Brandon

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Daryl Richter 2005-09-27 13:24:06 Re: how to do 'deep queries'?
Previous Message jeff sacksteder 2005-09-27 03:35:54 Re: how to do 'deep queries'?