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

Re: Check if table exists

From: David Saracini <dsaracini(at)yahoo(dot)com>
To: pgsql-novice(at)postgresql(dot)org, "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org>
Subject: Re: Check if table exists
Date: 2009-03-18 22:32:41
Message-ID: 277214.57681.qm@web82904.mail.mud.yahoo.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hi,

I'm a novice also, but I'm sure that one way of accomplishing this is to check the metadata table/views (eg. information_schema.tables).

If you want to make it a little cleaner, you could always wrap the check fo the meta into a function that returns a bool.

HTH,

David


--- On Wed, 3/18/09, Leif B. Kristensen <leif(at)solumslekt(dot)org> wrote:

> From: Leif B. Kristensen <leif(at)solumslekt(dot)org>
> Subject: [NOVICE] Check if table exists
> To: pgsql-novice(at)postgresql(dot)org
> Date: Wednesday, March 18, 2009, 11:55 AM
> Even if I've been using Postgres for some years, I
> figure that this 
> question fits best on this list:
> 
> How do I check if a table exists, eg. from a PLPGSQL
> function?
> 
> I've got a section of a function that only should be
> run if it's called 
> from a certain context, that is if the temporary table
> 'tmp_sources' is 
> found. But if I try with the line 
> 
>     IF EXISTS (SELECT * FROM tmp_sources) THEN
> 
> The function throws an error:
> 
>     ERROR: relation "tmp_sources" does not exist
> 
> Which is kind of off the mark in my context.
> -- 
> Leif Biberg Kristensen | Registered Linux User #338009
> Me And My Database: http://solumslekt.org/blog/
> 
> -
> Sent via pgsql-novice mailing list
> (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice

In response to

Responses

pgsql-novice by date

Next:From: David SaraciniDate: 2009-03-19 01:06:31
Subject: Changing transform_null_equals (and other settings)
Previous:From: Semyon ChaichenetsDate: 2009-03-18 17:21:23
Subject: Re: Check if table exists

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