EXISTS syntax for SELECT INTO?

EXISTS syntax for SELECT INTO?

am 11.10.2006 22:39:48 von Tony Grimes

I have a script that creates a table copy using SELECT INTO, but I want it
to check if the new table already exists first. Does SQL support the EXISTS
keyword for SELECT INTO statements (I'm running PG7)?

If not, is there another way to do it in SQL? I'd rather not do it
programmatically.

Thanks in advance,
Tony

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: EXISTS syntax for SELECT INTO?

am 11.10.2006 22:53:53 von Mike Morris

--Alt-Boundary-14681.440657390
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body

My advice:

Do a "drop table" first, ignoring any error that will result if it does not exist, then do the "select
into". This is portable, too...

> I have a script that creates a table copy using SELECT INTO, but I want it
> to check if the new table already exists first. Does SQL support the EXISTS
> keyword for SELECT INTO statements (I'm running PG7)?
>
> If not, is there another way to do it in SQL? I'd rather not do it
> programmatically.
>
> Thanks in advance,
> Tony
>


Mike Morris
The Music Place
1617 Willowhurst Avenue
San Jose, CA 95125
(408) 445-ARTS (2787)
------------------------------------
Your Free Humorous Quote:
When asked the difference between a tax collector and a taxidermist:
'The taxidermist takes only your skin.'
- Mark Twain
------------------------------------


--Alt-Boundary-14681.440657390--

Re: EXISTS syntax for SELECT INTO?

am 11.10.2006 23:04:32 von Tony Grimes

--B_3243423873_25095913
Content-type: text/plain; charset="ISO-8859-1"
Content-transfer-encoding: quoted-printable

Thanks Mike. Luckily, I don=B9t need the data if the table already exists so
that should work.

Tony


On 10/11/06 2:53 PM, "Mike Morris" wrote:

> My advice:
>=20
> Do a "drop table" first, ignoring any error that will result if it does n=
ot
> exist, then do the "select into". This is portable, too...
>=20
>> > I have a script that creates a table copy using SELECT INTO, but I wan=
t it
>> > to check if the new table already exists first. Does SQL support the E=
XISTS
>> > keyword for SELECT INTO statements (I'm running PG7)?
>> >=20
>> > If not, is there another way to do it in SQL? I'd rather not do it
>> > programmatically.
>> >=20
>> > Thanks in advance,
>> > Tony
>> >=20
>=20
>=20
> Mike Morris
> The Music Place
> 1617 Willowhurst Avenue
> San Jose, CA 95125
> (408) 445-ARTS (2787)
> ------------------------------------
>   =A0 Your Free Humorous Quote:
>       =A0 When asked the difference between a tax collector and a taxidermi=
st:
>       =A0 'The taxidermist takes only your skin.'
>                   =A0 - Mark Twain
> ------------------------------------
>=20



--B_3243423873_25095913--

Re: EXISTS syntax for SELECT INTO?

am 12.10.2006 02:16:51 von Chris

Tony Grimes wrote:
> I have a script that creates a table copy using SELECT INTO, but I want it
> to check if the new table already exists first. Does SQL support the EXISTS
> keyword for SELECT INTO statements (I'm running PG7)?
>
> If not, is there another way to do it in SQL? I'd rather not do it
> programmatically.

You could probably do it with a subquery:

select into table1 from table2 where not in (select id from table1);

Hopefully that gets you started :)

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php