Re: What is bad in this query ?

From: Rod Taylor <rbt(at)rbt(dot)ca>
To: Rado Petrik <r(dot)p(at)szm(dot)sk>
Cc: PostgreSQL-mailinglist <pgsql-sql(at)postgresql(dot)org>
Subject: Re: What is bad in this query ?
Date: 2003-05-02 14:32:52
Message-ID: 1051885971.94424.29.camel@jester
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, 2003-05-02 at 09:21, Rado Petrik wrote:
> Hi,
>
> What is bad in this query ?
>
> SELECT CASE
> WHEN EXIST(SELECT * FROM user WHERE name=rado)
> THEN (INSERT INTO user VALUES('rado'))
> END;

The INSERT is bad.

Try something like:
INSERT INTO user (name)
SELECT name FROM user WHERE name = 'rado';

--
Rod Taylor <rbt(at)rbt(dot)ca>

PGP Key: http://www.rbt.ca/rbtpub.asc

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-05-02 14:57:17 Re: timeofday() and now() issue..
Previous Message Matt Mello 2003-05-02 13:44:53 Re: implied FROM