create table if does not exists

From: Yan Cheng Cheok <yccheok(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: create table if does not exists
Date: 2010-01-08 02:10:04
Message-ID: 823238.36974.qm@web65702.mail.ac4.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I try to have the following stored procedure, to help me create tables, if the table does not exists (Is this a good practice by the way?)

if not exists(select * from information_schema.tables where table_name = 'MYTABLE') then

RAISE NOTICE 'table not there yet.';

CREATE TABLE MYTABLE
(
"value" text NOT NULL
);

end if;

When I run for the 2nd time, 'table not there yet.' still being printed out, al though I check through pgadmin, the MYTABLE is there.

May I know how I can fix this?

Thanks and Regards
Yan Cheng CHEOK

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris 2010-01-08 02:22:55 Re: create table if does not exists
Previous Message Tom Lane 2010-01-07 23:46:16 Re: A maybe-bug?