Re: SQL Rule

From: Oisin Glynn <me(at)oisinglynn(dot)com>
To: Bert <clemens(dot)bertschler(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL Rule
Date: 2006-04-25 21:41:05
Message-ID: 444E9771.803@oisinglynn.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Could you create the table without the C column
then create a view test_view with
select a,b,a+b as c,id from test;

Oisin

Bert wrote:
> Hi list
>
> I have a table construction like the one seen below, when i am updating
> or inserting i get a recurion, logical. But how to manage it that the
> rule is just doing it one time. Or is it possible to do the sum of a
> and b in an other way?
>
> CREATE TABLE test
> (
> a int2,
> b int2,
> c int2,
> id int2 NOT NULL,
> CONSTRAINT id_test PRIMARY KEY (id)
> )
> WITHOUT OIDS;
> ALTER TABLE test OWNER TO postgres;
>
>
> CREATE OR REPLACE RULE sum_op AS
> ON INSERT TO test DO UPDATE test SET c = new.a + new.b
> WHERE test.id = new.id;
>
> CREATE OR REPLACE RULE sum_op_up AS
> ON UPDATE TO test DO UPDATE test SET c = test.a + test.b
> WHERE test.id = new.id;
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend
>

In response to

  • SQL Rule at 2006-04-25 21:27:23 from Bert

Browse pgsql-general by date

  From Date Subject
Next Message Wayne Conrad 2006-04-25 22:02:30 Re: SQL Rule
Previous Message Wayne Conrad 2006-04-25 21:29:59 "ERROR: out of memory" during pg_restore