Re: Rule on tabel - Mailing list pgsql-general

From DeJuan Jackson
Subject Re: Rule on tabel
Date
Msg-id 3EC542CA.2000102@speedfc.com
Whole thread Raw
In response to Rule on tabel  (Markus.Schmitz <member29397@dbforums.com>)
List pgsql-general
Look at the docs for triggers and pay special attention to NEW/OLD you
want to change the value in NEW.increase and return it.  I'd give you a
more concrete example but I can't get to www.postgresql.org right now
myself.

Don't know if this is doable using a rule, and if it was you might get n
infinite recursion because rules are fired after the insert/update,
which means update happens to the row, rule fires and updates the row,
rule fires and updates the row, rule fires and updates the row, ....

Markus.Schmitz wrote:

>Hi their,
>I want to create a rule, whenever a specific row in a table is
>increased, another row is incremented.
>
>Let's say, I have a table like this:
>CREATE TABLE "test" (
>  "Code" VARCHAR(20) NOT NULL,
>  "Number" INTEGER NOT NULL,
>  "increase" INTEGER NOT NULL,
>  PRIMARY KEY("Code")
>)
>
>So, I want to have a rule (or trigger or whatever) which does the
>following job:
>
>Whenever the Number filed is updated and the new value is bigger than
>the old once, the increase field should be incremented (increase++).
>
>Can anybody tell me how to do so ?
>
>Thanks
>
>Markus
>
>--
>Posted via http://dbforums.com
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: Have you checked our extensive FAQ?
>
>http://www.postgresql.org/docs/faqs/FAQ.html
>
>


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: How return a refcusor using functions????
Next
From: "scott.marlowe"
Date:
Subject: Re: priority on a process