pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feeddrop table if exists
4+ messages / 3 participants
[nested] [flat]
* drop table if exists
@ 2001-07-03 21:24 Jason Watkins <jason_watkins@pobox.com>
0 siblings, 1 reply; 4+ messages in thread
From: Jason Watkins @ 2001-07-03 21:24 UTC (permalink / raw)
To: pgsql-sql
How can I duplicate the behavior of:
DROP TABLE IF EXISTS mytable;
CREATE TABLE mytable (
blah,
blah
);
INSERT INTO mytable
(blah)
VALUES
(blah);
in other words, so that I have a single sql file that restores the database
to a known state.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: drop table if exists
@ 2001-07-03 22:38 Philip Hallstrom <philip@adhesivemedia.com>
parent: Jason Watkins <jason_watkins@pobox.com>
0 siblings, 1 reply; 4+ messages in thread
From: Philip Hallstrom @ 2001-07-03 22:38 UTC (permalink / raw)
To: Jason Watkins <jason_watkins@pobox.com>; +Cc: pgsql-sql
Just drop the table using "DROP TABLE mytable;" and ignore the error...
I'm sure there are fancy ways of doing it by accessing system tables, but
the above works for me.
On Tue, 3 Jul 2001, Jason Watkins wrote:
> How can I duplicate the behavior of:
>
> DROP TABLE IF EXISTS mytable;
>
> CREATE TABLE mytable (
> blah,
> blah
> );
>
> INSERT INTO mytable
> (blah)
> VALUES
> (blah);
>
> in other words, so that I have a single sql file that restores the database
> to a known state.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: drop table if exists
@ 2001-07-03 23:05 Jason Watkins <jason_watkins@pobox.com>
parent: Philip Hallstrom <philip@adhesivemedia.com>
0 siblings, 0 replies; 4+ messages in thread
From: Jason Watkins @ 2001-07-03 23:05 UTC (permalink / raw)
To: pgsql-sql
Doesn't work. I like wrapping up the entire file in a transaction so that if
I make a stupid syntax error or the like, I can just do a rollback. Because
of that, the transaction enters abort state. I suppose I can just stop using
transactions and use this method.
^ permalink raw reply [nested|flat] 4+ messages in thread
* RE: Re: drop table if exists
@ 2001-07-17 10:16 Maxim Maletsky <maxim@japaninc.com>
0 siblings, 0 replies; 4+ messages in thread
From: Maxim Maletsky @ 2001-07-17 10:16 UTC (permalink / raw)
To: 'Philip Hallstrom' <philip@adhesivemedia.com>; Jason Watkins <jason_watkins@pobox.com>; +Cc: pgsql-sql
Alright, but what about when you're writing a long dump file with all these
sequences, functions not speaking about the tables themselves.
When I drop something I wanna make sure it out the database (but still
cannot empty the whole database before), so I have
DROP TABLE ..., ..., ..., ...;
DROP FUNCTION ..., ..., ..., ...;
DROP SEQUENCE ..., ..., ..., ...;
If one of these were not there, the whole dump crashes and I need to restart
the process modifying the SQL file.
I'd LOVE to have a magic 'IF EXISTS' like in mySQL - make life easier
(Although I totally disrespect mySQL).
Has anyone a work around for this?
Thanks,
and yes, sorry for the late post, just looked you up guys.
Sincerely,
Maxim Maletsky
Founder, Chief Developer
PHPBeginner.com (Where PHP Begins)
maxim@phpbeginner.com
www.phpbeginner.com
-----Original Message-----
From: Philip Hallstrom [mailto:philip@adhesivemedia.com]
Sent: Wednesday, July 04, 2001 7:39 AM
To: Jason Watkins
Cc: pgsql-sql@postgresql.org
Subject: [SQL] Re: drop table if exists
Just drop the table using "DROP TABLE mytable;" and ignore the error...
I'm sure there are fancy ways of doing it by accessing system tables, but
the above works for me.
On Tue, 3 Jul 2001, Jason Watkins wrote:
> How can I duplicate the behavior of:
>
> DROP TABLE IF EXISTS mytable;
>
> CREATE TABLE mytable (
> blah,
> blah
> );
>
> INSERT INTO mytable
> (blah)
> VALUES
> (blah);
>
> in other words, so that I have a single sql file that restores the
database
> to a known state.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
>
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2001-07-17 10:16 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-07-03 21:24 drop table if exists Jason Watkins <jason_watkins@pobox.com>
2001-07-03 22:38 ` Philip Hallstrom <philip@adhesivemedia.com>
2001-07-03 23:05 ` Jason Watkins <jason_watkins@pobox.com>
2001-07-17 10:16 RE: Re: drop table if exists Maxim Maletsky <maxim@japaninc.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