How to check if a table exists from functions.

From: mikael(dot)kjellstrom(at)_no_spam_flygtaxi(dot)se (Mikael Kjellstrm)
To: pgsql-sql(at)postgresql(dot)org
Subject: How to check if a table exists from functions.
Date: 2001-06-19 14:04:38
Message-ID: Xns90C5A38888F9Fmikaelkjellstromnosp@206.221.255.129
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


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?

Is there a more simple way to check if a table exists?

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David BOURIAUD 2001-06-19 14:38:44 Re: About primary keys.
Previous Message Roberto Mello 2001-06-19 13:49:18 Re: About primary keys.