pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedsql scripts
4+ messages / 4 participants
[nested] [flat]
* sql scripts
@ 2003-10-19 02:37 Sam Carleton <ehc@linux-info.net>
0 siblings, 1 reply; 4+ messages in thread
From: Sam Carleton @ 2003-10-19 02:37 UTC (permalink / raw)
To: pgsql-admin
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: sql scripts
@ 2003-10-20 17:30 David F. Skoll <dfs@roaringpenguin.com>
parent: Sam Carleton <ehc@linux-info.net>
0 siblings, 0 replies; 4+ messages in thread
From: David F. Skoll @ 2003-10-20 17:30 UTC (permalink / raw)
To: pgsql-admin
On Sat, 18 Oct 2003, Sam Carleton wrote:
> 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.
As far as I know, there is no way to do that in PostgreSQL's standard
SQL language. But it doesn't matter -- as long as the DROP TABLE
command is in it's own transaction, you can unconditionally drop the table
and ignore any errors.
Regards,
David.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: sql scripts
@ 2003-10-20 18:33 Murthy Kambhampaty <murthy.kambhampaty@goeci.com>
0 siblings, 0 replies; 4+ messages in thread
From: Murthy Kambhampaty @ 2003-10-20 18:33 UTC (permalink / raw)
To: Sam Carleton <ehc@linux-info.net>; 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@linux-info.net]
>Sent: Saturday, October 18, 2003 22:37
>To: pgsql-admin@postgresql.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@postgresql.org so that your
> message can get through to the mailing list cleanly
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: sql scripts
@ 2003-10-20 19:50 Priya G <sreepriya@hotmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Priya G @ 2003-10-20 19:50 UTC (permalink / raw)
To: ehc@linux-info.net; pgsql-admin
<html><div style='background-color:'><DIV>
<P>Use pg_dump -c</P>
<P>this will drop the db objects before creating them</P>
<P>Priya<BR><BR></P></DIV>
<DIV></DIV>>From: Sam Carleton <EHC@LINUX-INFO.NET>
<DIV></DIV>>To: pgsql-admin@postgresql.org
<DIV></DIV>>Subject: [ADMIN] sql scripts
<DIV></DIV>>Date: Sat, 18 Oct 2003 22:37:00 -0400
<DIV></DIV>>
<DIV></DIV>>I am new to postgres and your mailing lists, please let me know if I
<DIV></DIV>>am posting in the wrong list.
<DIV></DIV>>
<DIV></DIV>>I am working on creating my first database in Postgres. In the
<DIV></DIV>>script that will create all the tables for the firs time, I would
<DIV></DIV>>like to have a conditional statement to delete a table, if it
<DIV></DIV>>already exists. I know the other databases create such a condtional
<DIV></DIV>>statement for you when you export the schema. What would such a
<DIV></DIV>>conditional statement look like in Postgres's sql?
<DIV></DIV>>
<DIV></DIV>>sam
<DIV></DIV>>
<DIV></DIV>>---------------------------(end of broadcast)---------------------------
<DIV></DIV>>TIP 3: if posting/reading through Usenet, please send an appropriate
<DIV></DIV>> subscribe-nomail command to majordomo@postgresql.org so that your
<DIV></DIV>> message can get through to the mailing list cleanly
<DIV></DIV></div><br clear=all><hr> <a href="http://g.msn.com/8HMAENUS/2749??PS=">Fretting that your Hotmail account may expire because you forgot to sign in enough? Get Hotmail Extra Storage today! </a> </html>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2003-10-20 19:50 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-10-19 02:37 sql scripts Sam Carleton <ehc@linux-info.net>
2003-10-20 17:30 ` David F. Skoll <dfs@roaringpenguin.com>
2003-10-20 18:33 Re: sql scripts Murthy Kambhampaty <murthy.kambhampaty@goeci.com>
2003-10-20 19:50 Re: sql scripts Priya G <sreepriya@hotmail.com>
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