Re: How to check if a table exists

From: "Tim Barnard" <tbarnard(at)povn(dot)com>
To: "Jeff Lu" <jklcom(at)mindspring(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to check if a table exists
Date: 2001-03-08 16:51:24
Message-ID: 00d801c0a7f0$032945c0$a519af3f@hartcomm.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Test result of PQexec() using PQresultstatus(). On success you'll get a
PGRES_TUPLES_OK result.
Your subsequent call to PQfname() will contain the word "count" and a
similar call to PQgetvalue() will contain count's value, as a string of
course. If count = 0, table missing. If count = 1, table is present.

Checkout the source for psql to see how to use aforementioned functions.

Have fun ;-)

Tim

----- Original Message -----
From: "Jeff Lu" <jklcom(at)mindspring(dot)com>
To: "Tim Barnard" <tbarnard(at)povn(dot)com>
Sent: Thursday, March 08, 2001 8:25 PM
Subject: RE: [GENERAL] How to check if a table exists

> Thanks Tim,
>
> What's the syntax for testing count? Is count a variable?
>
> Thanks
> -Jeff
>
> -----Original Message-----
> From: Tim Barnard [mailto:tbarnard(at)povn(dot)com]
> Sent: Thursday, March 08, 2001 11:16 AM
> To: Jeff
> Cc: pgsql-general(at)postgresql(dot)org
> Subject: Re: [GENERAL] How to check if a table exists
>
>
> I do it this way using libpq: select count(*) from pg_class where
> relname='table name goes here'
> and test for a count > 1.
>
> Tim
>
> ----- Original Message -----
> From: "Jeff" <jklcom(at)mindspring(dot)com>
> To: <pgsql-general(at)postgresql(dot)org>
> Sent: Wednesday, March 07, 2001 8:48 PM
> Subject: [GENERAL] How to check if a table exists
>
>
> > Also how to programmatically check if a table exists in the database?
> >
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister command
> > (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
> >
>
>

Browse pgsql-general by date

  From Date Subject
Next Message Barry Lind 2001-03-08 16:56:56 Re: length of insert stmt?
Previous Message Tim Barnard 2001-03-08 16:16:04 Re: How to check if a table exists