DO INSTEAD in rule

From: Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp>
To: pgsql-sql(at)postgresql(dot)org
Subject: DO INSTEAD in rule
Date: 2004-01-04 13:51:15
Message-ID: 20040104.225115.71101762.t-ishii@sra.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

In the last SELECT I exepcted j = 0, rather than j = 1 since I use DO
INSTEAD in the rule and the default value for j is 0. Am I missing
something?

DROP TABLE t1 CASCADE;
DROP TABLE
CREATE TABLE t1 (
i INTEGER,
j INTEGER DEFAULT 0
);
CREATE TABLE
CREATE rule t1_ins AS ON INSERT TO t1
WHERE (EXISTS (SELECT 1 FROM t1
WHERE i = new.i))
DO INSTEAD UPDATE t1 SET j = j + 1
WHERE i = new.i;
CREATE RULE
INSERT INTO t1 VALUES (1);
INSERT 1690668 1
SELECT * FROM t1;
i | j
---+---
1 | 1
(1 row)
--
Tatsuo Ishii

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2004-01-04 17:48:26 Re: DO INSTEAD in rule
Previous Message John Coryat 2004-01-03 09:20:46 Complex Update