rule on insert with default values for new instance - Mailing list pgsql-general

From Janning Vygen
Subject rule on insert with default values for new instance
Date
Msg-id 01061912505602.01139@janning
Whole thread Raw
Responses Re: rule on insert with default values for new instance  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi,

if i have a table and a rule like this

CREATE TABLE user (id SERIAL, name text);

CREATE RULE startaccount AS ON INSERT
    TO user
    DO INSERT INTO account (name) VALUES
    (new.id, new.name);

(i didnt check the syntax, hope you still get the point)

i get problems because it seems to me that new.id is not defined at the
moment i do the insert. the default value seems not to be calculated at this
time.

How can i get around this?

im quite new to sql and mabye there is a misunderstanding of the rule feature.

please give me a hint.
thanks in advance for any help.

janning

does anybody know a good book/website like an SQL cookbook with many many
examples to learn from?


pgsql-general by date:

Previous
From: "Richard Huxton"
Date:
Subject: Re: front ends for postgres under linux
Next
From: Penguin
Date:
Subject: Re: front ends for postgres under linux