Search Postgresql Archives

Re: pl sql to check if table of table_name exists

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Shaun Clements wrote:

Hi

Hate to ask, but it isnt obvious to me from the documentation.
How do I perform a query in pgplsql, to check it a table exists of a particular name.


Check the manual. There are two ways to d othis. You could query the data catalogs directly (something like count(*) from pg_class where relname = $1), but this is not preferred because you have the possibilities that the data catalogs will be changed in the future.

The better way to do this is to query the information schema. I forget the table name but it may be something like (select count(*) from information_schema.tables where table_name = $1). the structure of the information schema is defined in the SQL standards and will be stable between versions.

Best Wishes,
Chris Travers
Metatron Technology COnsulting

Thanks in advance

Kind Regards,
Shaun Clements



---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux