drop table before create

Started by Mark Probertover 20 years ago3 messagesgeneral
Jump to latest
#1Mark Probert
probertm@acm.org

Hi ..

I have not been able to work out how to do this is Postgres 8
(pseudo-code)

if exists table foo
drop table foo;
end
create table foo;

If I go with

drop table foo;
create table foo;

then it barfs on an empty db. I can find the table name in pg_class but
I am not sure of where to go from there.

The assumption here is that the SQL is coming in on a script via the
programmatic interface. Slurp in a bunch of SQL commands and then fire
them at the database.

Perhaps it is just easier to 'dropdb' then 'createdb' and go from there.

Many thanks,

--
-mark. (probertm at acm dot org)

#2Lee Harr
missive@hotmail.com
In reply to: Mark Probert (#1)
Re: drop table before create

I have not been able to work out how to do this is Postgres 8
(pseudo-code)

if exists table foo
drop table foo;
end
create table foo;

If I go with

drop table foo;
create table foo;

then it barfs on an empty db.

The assumption here is that the SQL is coming in on a script via the
programmatic interface. Slurp in a bunch of SQL commands and then fire
them at the database.

There are a couple of commands that may help you:

\set ON_ERROR_STOP
\unset ON_ERROR_STOP

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

#3A. Kretschmer
akretschmer@despammed.com
In reply to: Lee Harr (#2)
Re: drop table before create

am 26.08.2005, um 2:11:30 +0430 mailte Lee Harr folgendes:

I have not been able to work out how to do this is Postgres 8
(pseudo-code)
if exists table foo
drop table foo;
end
create table foo;
If I go with
drop table foo;
create table foo;
then it barfs on an empty db.

Perhaps this will help you:
http://www.milwaukeesoft.com/forums/viewtopic.php?t=79&sid=e9281cc9522a6b3c91b33407692c5db4

Regards, Andreas
--
Andreas Kretschmer (Kontakt: siehe Header)
Heynitz: 035242/47212, D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
=== Schollglas Unternehmensgruppe ===