Re: executing delete in a case statement?

From: Richard Huxton <dev(at)archonet(dot)com>
To: Jean-Christian Imbeault <jc(at)mega-bucks(dot)co(dot)jp>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: executing delete in a case statement?
Date: 2002-11-05 10:42:21
Message-ID: 200211051042.21973.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tuesday 05 Nov 2002 10:03 am, Jean-Christian Imbeault wrote:
> What is the proper way to execute a delete statement (if possible) in a
> case statement. I am trying various versions of the following but can't
> get it to work:
>
> "select member_id, case when (select count(buy_later) from cart_li where
> member_id=cart_id AND buy_later=true) > 0 then (delete from cart_li
> where cart_id=10) end from carts"

The "case" is supposed to be returning a value not taking actions. SQL is not
a procedural language like C/Perl/PHP etc.

SELECT a,
CASE WHEN a=1 THEN 'one'
WHEN a=2 THEN 'two'
ELSE 'other'
END
FROM test;

See "functions and operators" in the manual for details.

--
Richard Huxton

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2002-11-05 10:47:39 Re: log file?
Previous Message Danil Kovtunovich 2002-11-05 10:31:43 Regarding to the PostgreSQL Manager announce