pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Rowell <richard@bowmansystems.com>
To: pgsql-sql@postgresql.org
Subject: Database Upgrade scripts (AKA Conditional SQL execution)
Date: 07 Jul 2003 08:58:42 -0500
Message-ID: <1057586322.31898.18.camel@localhost> (raw)

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@bowmansystems.com>

Attachments:

  signature.asc (application/pgp-signature, 188B) download

view thread (2+ messages)  latest in thread

Message-ID: <1057586322.31898.18.camel@localhost>
Permalink:  ../1057586322.31898.18.camel@localhost/
Also on:    postgresql.org/message-id/1057586322.31898.18.camel@localhost

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: richard@bowmansystems.com
  Subject: Re: Database Upgrade scripts (AKA Conditional SQL execution)
  In-Reply-To: <1057586322.31898.18.camel@localhost>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox