Re: Check If PostgreSQL Table Exists

From: Madison Kelly <linux(at)alteeve(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Check If PostgreSQL Table Exists
Date: 2006-01-01 18:24:29
Message-ID: 43B81E5D.8040508@alteeve.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

dhilchrist(at)gmail(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-01-01 18:40:08 Re: pg_reload_conf() does not unset archive_command
Previous Message Andrus Moor 2006-01-01 17:56:16 Last line is not read from postgres.conf