Re: Column existence - how to check? - Mailing list pgsql-general

From Jeff Boes
Subject Re: Column existence - how to check?
Date
Msg-id 9pf6c1$14vi$1@news.tht.net
Whole thread Raw
In response to Column existence - how to check?  ("Mark Higgins" <mghiggins@my-deja.com>)
List pgsql-general
In article <20011002.213141.2025187190.16719@localhost.localdomain>, "Mark
Higgins" <mghiggins@my-deja.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@nexcerpt.com

pgsql-general by date:

Previous
From: Neal Lindsay
Date:
Subject: Sub-select testing group membership (Arrays)
Next
From: Mark Gordon
Date:
Subject: Scalability of postgresql.