Re: Check if table exists - Mailing list pgsql-novice

From Semyon Chaichenets
Subject Re: Check if table exists
Date
Msg-id 6f81e0890903181021g2046c0p8f3b06aff8fff711@mail.gmail.com
Whole thread Raw
In response to Check if table exists  ("Leif B. Kristensen" <leif@solumslekt.org>)
List pgsql-novice
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
>

pgsql-novice by date:

Previous
From: "Leif B. Kristensen"
Date:
Subject: Re: Check if table exists
Next
From: David Saracini
Date:
Subject: Re: Check if table exists