Re: sql scripts

From: Murthy Kambhampaty <murthy(dot)kambhampaty(at)goeci(dot)com>
To: 'Sam Carleton' <ehc(at)linux-info(dot)net>, pgsql-admin(at)postgresql(dot)org
Subject: Re: sql scripts
Date: 2003-10-20 18:33:24
Message-ID: 2D92FEBFD3BE1346A6C397223A8DD3FC092444@THOR.goeci.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

If it's a bash script you could use:

#####
SomeTable=<Table you're about to create>
TableTest=$(psql -d <your new db> -U <its owner> -ntc "select relname from
pg_class where relname='$SomeTable'")
[[ -n "$TableTest" ]] && psql -d <your new db> -U <its owner> -nc "drop
table $SomeTable"
#####

It's not quite "in postgres's sql", but it could get the job done

>-----Original Message-----
>From: Sam Carleton [mailto:ehc(at)linux-info(dot)net]
>Sent: Saturday, October 18, 2003 22:37
>To: pgsql-admin(at)postgresql(dot)org
>Subject: [ADMIN] sql scripts
>
>
>I am new to postgres and your mailing lists, please let me know if I
>am posting in the wrong list.
>
>I am working on creating my first database in Postgres. In the
>script that will create all the tables for the firs time, I would
>like to have a conditional statement to delete a table, if it
>already exists. I know the other databases create such a condtional
>statement for you when you export the schema. What would such a
>conditional statement look like in Postgres's sql?
>
>sam
>
>---------------------------(end of
>broadcast)---------------------------
>TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

Browse pgsql-admin by date

  From Date Subject
Next Message Naomi Walker 2003-10-20 18:38:52 Re: Restore Problem
Previous Message Hannu Krosing 2003-10-20 17:50:22 Re: [PERFORM] Low Insert/Update Performance