Re: AUTO_INCREMENT patch - Mailing list pgsql-hackers

From des@des.no (Dag-Erling Smørgrav)
Subject Re: AUTO_INCREMENT patch
Date
Msg-id xzpd6fnwpyb.fsf@dwp.des.no
Whole thread Raw
In response to Re: AUTO_INCREMENT patch  (Rod Taylor <rbt@rbt.ca>)
Responses Re: AUTO_INCREMENT patch
List pgsql-hackers
Rod Taylor <rbt@rbt.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@des.no


pgsql-hackers by date:

Previous
From: Carlos Guzman Alvarez
Date:
Subject: Re: Identification of serial fields
Next
From: Rod Taylor
Date:
Subject: Re: AUTO_INCREMENT patch