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

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 (view raw or flat)
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

pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group