X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id B66C59FB30D for ; Wed, 16 Aug 2006 15:45:29 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 86914-03 for ; Wed, 16 Aug 2006 18:45:01 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.189]) by postgresql.org (Postfix) with ESMTP id 6148D9FB2F2 for ; Wed, 16 Aug 2006 15:45:00 -0300 (ADT) Received: by nf-out-0910.google.com with SMTP id p77so853197nfc for ; Wed, 16 Aug 2006 11:44:59 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=BFtgvARgg/wtfA4HC6TGXldfvMuflukq5n8d8NOtTtgxxFGeTcby7BkpXXlTey67XflKYKd5BZNXCDJ/HXWbSTJaWYtAIrI0MC9t0kdfucjJAEcaPs9c+1kggPXhyVmmFovw3/NosSON3DOkhpin4i/x9Dmr9UqcQXifX7OFmdU= Received: by 10.49.8.1 with SMTP id l1mr1086370nfi; Wed, 16 Aug 2006 11:44:58 -0700 (PDT) Received: by 10.48.215.12 with HTTP; Wed, 16 Aug 2006 11:44:58 -0700 (PDT) Message-ID: <4f4c2a010608161144v61381db8m2d9148915673757d@mail.gmail.com> Date: Wed, 16 Aug 2006 14:44:58 -0400 From: "Jon Horsman" To: pgsql-sql@postgresql.org Subject: DB creation script questions MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.199 tagged_above=0 required=5 tests=DNS_FROM_RFC_ABUSE, SPF_PASS X-Spam-Level: X-Archive-Number: 200608/123 X-Sequence-Number: 26081 Hey All, I'm new to postgres and am wondering what the recommended way of creating an automated db creation script is. I've reading the postgres 8.1 manual but haven't seen much on this and google doesn't seem to be bringing up much either. I need to create a script that will create a database if it currently doesn't exist on the system. It will then create tables if they don't already exist and populate the tables with some data if this data doesn't currently exist. This script must be able to be run over an over without causing harm to the db. I have previously used MySQL and was able to accomplish this very simply using IF NOT EXISTS for the table and database creation but this doesn't seem to be available for postgres and i'm looking for a more robust solution anyways. Is there a way that from a sql script file/shell script you can find out if certain postgres tables/databases exist? If someone can point me in the right direction it would be greatly appreciated. Thanks, Jon.