Re: Column existence - how to check?

From: "Jeff Boes" <jboes(at)nexcerpt(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Column existence - how to check?
Date: 2001-10-03 14:13:40
Message-ID: 9pf6c1$14vi$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In article <20011002(dot)213141(dot)2025187190(dot)16719(at)localhost(dot)localdomain>, "Mark
Higgins" <mghiggins(at)my-deja(dot)com> wrote:

> I'm writing an app that dynamically creates tables in a postgresql db.
>
> I'd like to determine if a column has been defined for a known table. Is
> there any way to do this? I've searched around quite a bit and haven't
> found anything.

Well, if your app is written in Perl, and you are using DBD::Pg, then you
can do something like this:

my $sth = $dbh->prepare('select * from mytable');
$sth->execute or die $dbh->errstr;
my @cols = @{ $sth->{NAME_lc} };
if (grep($_ eq 'col_i_want', @cols)) { ... }

--
Jeff Boes vox 616.226.9550
Database Engineer fax 616.349.9076
Nexcerpt, Inc. jboes(at)nexcerpt(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Mark Gordon 2001-10-03 16:34:31 Scalability of postgresql.
Previous Message Neal Lindsay 2001-10-03 12:52:49 Sub-select testing group membership (Arrays)