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

Check if table exists

From: "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org>
To: pgsql-novice(at)postgresql(dot)org
Subject: Check if table exists
Date: 2009-03-18 16:55:37
Message-ID: 200903181755.38024.leif@solumslekt.org (view raw or flat)
Thread:
Lists: pgsql-novice
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/

Responses

pgsql-novice by date

Next:From: Leif B. KristensenDate: 2009-03-18 17:13:15
Subject: Re: Check if table exists
Previous:From: Ed HudspethDate: 2009-03-18 15:02:07
Subject: Service start up error "The service name is invalid net helpmsg 2185"

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