Обсуждение: sql scripts

Поиск
Список
Период
Сортировка

sql scripts

От
Sam Carleton
Дата:
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

Re: sql scripts

От
"David F. Skoll"
Дата:
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.

Re: sql scripts

От
Murthy Kambhampaty
Дата:
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
>

Re: sql scripts

От
"Priya G"
Дата:
<div style="background-color:"><div><p>Use pg_dump -c<p>this will drop the db objects before creating them<p>Priya<br
/><br/></div><div></div>>From: Sam Carleton  <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
postgresand your mailing lists, please let me know if I <div></div>>am posting in the wrong list. <div></div>>
<div></div>>Iam working on creating my first database in Postgres. In the <div></div>>script that will create all
thetables for the firs time, I would <div></div>>like to have a conditional statement to delete a table, if it
<div></div>>alreadyexists. I know the other databases create such a condtional <div></div>>statement for you when
youexport 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
canget through to the mailing list cleanly <div></div></div><br clear="all" /><hr /><a
href="http://g.msn.com/8HMAENUS/2749??PS=">Frettingthat your Hotmail account may expire because you forgot to sign in
enough?Get Hotmail Extra Storage today! </a>