Re: How to check if a table exists from functions. - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: How to check if a table exists from functions.
Date
Msg-id Pine.BSF.4.21.0106201421270.99731-100000@megazone23.bigpanda.com
Whole thread Raw
In response to How to check if a table exists from functions.  (mikael.kjellstrom@_no_spam_flygtaxi.se (Mikael Kjellström))
List pgsql-sql
On Tue, 19 Jun 2001, Mikael Kjellstr�m wrote:

> 
> Maybe I am doing this the wrong way, but how do I check if a table exist?
> 
> This works from psql:
> 
> select
>   relname
> from
>   pg_class
> where
>   relname = 'tablename'
> 
> 
> But if I try to do the same from a PL/PGSQL stored procedure I get the 
> following error message:
> 
> ERROR:  unexpected SELECT query in exec_stmt_execsql()
> 
> Isn't select's allowed from stored procedures?

You'll want to use something like:
declarefoo name;
begin...select relname INTO foo from pg_class whererelname=''tablename'';...
end;




pgsql-sql by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Using the extract() function in plpgsql
Next
From: clayton cottingham
Date:
Subject: commentds on redhats new database