Обсуждение: How to check if a table exists from functions.
How to check if a table exists from functions.
От
mikael.kjellstrom@_no_spam_flygtaxi.se (Mikael Kjellström)
Дата:
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?
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;