Rod Taylor <[EMAIL PROTECTED]> 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 - [EMAIL PROTECTED]

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]

Reply via email to