pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bo Lorentsen <bl@netgroup.dk>
To: Bhuvan A <bhuvansql@yahoo.com>
Cc: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Re: checking for existence of a table in plpgsql.
Date: 14 Mar 2002 09:06:39 +0100
Message-ID: <1016093199.669.20.camel@netgroup> (raw)
In-Reply-To: <Pine.LNX.4.20.0203141101100.32557-100000@Larry>
References: <Pine.LNX.4.20.0203141101100.32557-100000@Larry>

On Thu, 2002-03-14 at 06:40, Bhuvan A wrote:
> how can one know that a particular table exists or not in plpgsql?
How about :

SELECT INTO cnt count( * ) FROM pg_class WHERE relname='mytable';
IF FOUND THEN 
	...
END IF;

or 

IF cnt > 0 THEN 
	...
END IF;

This plpgsql snip, will find the number of classes that have the
"mytable" name.

Would this do the trick ? 

/BL




view thread (3+ messages)  latest in thread

Message-ID: <1016093199.669.20.camel@netgroup>
Permalink:  ../1016093199.669.20.camel@netgroup/
Also on:    postgresql.org/message-id/1016093199.669.20.camel@netgroup

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bl@netgroup.dk, bhuvansql@yahoo.com
  Subject: Re: checking for existence of a table in plpgsql.
  In-Reply-To: <1016093199.669.20.camel@netgroup>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox