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