Database Upgrade scripts (AKA Conditional SQL execution)

From: Richard Rowell <richard(at)bowmansystems(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Database Upgrade scripts (AKA Conditional SQL execution)
Date: 2003-07-07 13:58:42
Message-ID: 1057586322.31898.18.camel@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Moving to Postgres from MS SQL server wherever I can. When writing
database upgrade scripts, it is nice to construct the script so it will
run correctly even if run twice. In MS-SQL's TSQL I would do something
like this:

IF( SELECT COUNT(*) FROM sysobjects WHERE name = 'foo' AND type ='U' ) <
1 THEN
CREATE TABLE foo()
END

Can I accomplish this with postgresql without involving an external
process (like say perl)? I guess I could put the upgrade stuff into
PL/SQL functions and just drop the functions when I'm done, but I was
hoping for something a little "cleaner".

--
Richard Rowell <richard(at)bowmansystems(dot)com>

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Schmitz 2003-07-07 14:14:14 sort for ranking
Previous Message Gary Stainburn 2003-07-07 13:12:35 Re: Concat and view - Re: create view error