Re: inserting via "on insert" rule - Mailing list pgsql-general

From Andreas Fromm
Subject Re: inserting via "on insert" rule
Date
Msg-id 3F565107.8090007@physik.uni-erlangen.de
Whole thread Raw
In response to Re: inserting via "on insert" rule  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-general
Peter Eisentraut wrote:

>Andreas Fromm writes:
>
>
>
>>I was thinking of defining a view "users" over "persons" which would let
>>me retrive the list of useres. But How would I implement the rule for
>>insertiung users? I tryed the following but NEW is not known where I
>>want to use it:
>>
>>CREATE VIEW users AS
>>    SELECT * FROM persons WHERE is_user(person.id) = TRUE;
>>
>>CREATE RULE insert_on_users AS ON INSERT
>>    TO users DO INSTEAD
>>        INSERT INTO persons SELECT * FROM NEW;
>>
>>
>
>You can write
>
>... DO INSTEAD INSERT INTO persons VALUES (NEW.col1, NEW.col2, ...);
>
>
>
Yes, but the advantage of the select would be that I could do a SELECT
.. FROM .. WHERE , or how can I perform a checking of the data before
insertion?

Andreas



pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: setting last_value of sequence
Next
From: Greg Stark
Date:
Subject: Re: Optimizer picks an ineffient plan