Re: AUTO_INCREMENT patch

From: des(at)des(dot)no (Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?=)
To: Rod Taylor <rbt(at)rbt(dot)ca>
Cc: PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: AUTO_INCREMENT patch
Date: 2003-08-03 00:21:48
Message-ID: xzpd6fnwpyb.fsf@dwp.des.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Rod Taylor <rbt(at)rbt(dot)ca> writes:
> CREATE OR REPLACE RULE rulename AS ON INSERT
> TO tablename
> DO INSTEAD
> INSERT INTO tablename
> ( id, col1, ...)
> VALUES ( DEFAULT, NEW.col1, ...);
>

I now have a patch that adds support for the GENERATED ... AS ...
syntax and implements the "GENERATED BY DEFAULT AS IDENTITY" case.
I'm trying to figure out how to implement the other two cases
("GENERATED ALWAYS AS IDENTITY" and "GENERATED ALWAYS AS ( expr )").
I thought I'd try your trick:

des=# create table test ( id serial, word text );
NOTICE: CREATE TABLE will create implicit sequence "test_id_seq" for SERIAL column "test.id"
CREATE TABLE
des=# create rule test_id_generate as
des-# on insert to test do instead
des-# insert into test ( id, word ) values ( default, new.word );
CREATE RULE
des=# insert into test ( id, word ) values ( 42, 'hello' );
ERROR: infinite recursion detected in rules for relation "test"
des=# insert into test ( word ) values ( 'hello' );
ERROR: infinite recursion detected in rules for relation "test"

any suggestions?

DES
--
Dag-Erling Smørgrav - des(at)des(dot)no

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Rod Taylor 2003-08-03 00:56:25 Re: AUTO_INCREMENT patch
Previous Message Carlos Guzman Alvarez 2003-08-02 23:42:49 Re: Identification of serial fields

Browse pgsql-patches by date

  From Date Subject
Next Message Rod Taylor 2003-08-03 00:56:25 Re: AUTO_INCREMENT patch
Previous Message Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?= 2003-08-02 20:52:15 Re: AUTO_INCREMENT patch