Re: Rules and conditions - Mailing list pgsql-general

From Guillaume Lelarge
Subject Re: Rules and conditions
Date
Msg-id 200912091321.22168.guillaume@lelarge.info
Whole thread Raw
In response to Re: Rules and conditions  (George Silva <georger.silva@gmail.com>)
List pgsql-general
Le mercredi 9 décembre 2009 à 12:38:33, George Silva a écrit :
> Hello guys,
>
> Still having some trouble with this.
>
> I'm trying to use a case when, but postgres is still giving me syntax
>  error.
>
> CREATE OR REPLACE RULE instead_update AS ON UPDATE TO foo
> DO INSTEAD
> (
> CASE SELECT exists(SELECT 1 FROM versioning.foo_version_1 WHERE
> OLD.oid = NEW.oid) as a WHEN a=true THEN
>         UPDATE versioning.foo_version_1 SET
>             oid = new.oid,
>             att1 = new.att1,
>             att2 = new.att2,
>             the_geom = new.the_geom,
>             status = 'UPDATE'
>         WHERE oid = new.oid;
>     WHEN a=false THEN
>         INSERT INTO versioning.foo_version_1(NEW.*,'UPDATE');
> END
> );
>
> Any thoughts?
>

You can't use the CASE structure this way. You really need to use a stored
function.


--
Guillaume.
 http://www.postgresqlfr.org
 http://dalibo.com

pgsql-general by date:

Previous
From: Postgre Novice
Date:
Subject: ERROR: could not open relation with OID 59132
Next
From: Jaime Casanova
Date:
Subject: Re: Implementing next 30 (or so) rows "sliding window"