Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

Re: Check if table exists



Try

IF EXISTS (SELECT * FROM pg_table WHERE tablename=tmp_sources)
 THEN
 -- table exists

Alternatively, you could try catching the exception in your original
code and handling it.

 IF EXISTS (SELECT * FROM tmp_sources) THEN
    -- table or view exists
    EXCEPTION

Semyon

> How do I check if a table exists, eg. from a PLPGSQL function?
>    IF EXISTS (SELECT * FROM tmp_sources) THEN
>
> The function throws an error:
>
>    ERROR: relation "tmp_sources" does not exist
>



Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group