Re: Rules and conditions

From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: pgsql-general(at)postgresql(dot)org
Cc: George Silva <georger(dot)silva(at)gmail(dot)com>
Subject: Re: Rules and conditions
Date: 2009-12-09 12:21:22
Message-ID: 200912091321.22168.guillaume@lelarge.info
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message AlexeyChe 2009-12-09 13:33:22 C functions, dll, server fall down
Previous Message Stephen Tyler 2009-12-09 12:11:27 Re: Excessive (and slow) fsync() within single transaction