Re: Check If PostgreSQL Table Exists - Mailing list pgsql-general

From Madison Kelly
Subject Re: Check If PostgreSQL Table Exists
Date
Msg-id 43B81E5D.8040508@alteeve.com
Whole thread Raw
In response to Check If PostgreSQL Table Exists  (dhilchrist@gmail.com)
List pgsql-general
dhilchrist@gmail.com wrote:
> Dear All,
>
> How To Check If PostgreSQL Table Exists in the Database Using Perl.
>
> Dhilchrist

Here is what I do...

$DBreq=$DB->prepare("SELECT COUNT(*) FROM pg_tables WHERE
tablename='foo'") || die $DBI::errstr;
$DBreq->execute();
my ($table_num)=$DBreq->fetchrow_array();
if ( $table_num < 1 )
{
    # Create the missing table
}
else
{
    # It exists!
}

Hope that helps!

Madison


pgsql-general by date:

Previous
From: Scott Ribe
Date:
Subject: Re: storing PDFs
Next
From: "Andrus Moor"
Date:
Subject: pg_reload_conf() does not unset archive_command