Re: Check if table exists

From: Semyon Chaichenets <pgsql-novice(at)semyon(dot)net>
To: "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Check if table exists
Date: 2009-03-18 17:21:23
Message-ID: 6f81e0890903181021g2046c0p8f3b06aff8fff711@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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
>

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message David Saracini 2009-03-18 22:32:41 Re: Check if table exists
Previous Message Leif B. Kristensen 2009-03-18 17:13:15 Re: Check if table exists