Unix Technical Forum

INSTEAD OF trigger on VIEWs

This is a discussion on INSTEAD OF trigger on VIEWs within the pgsql Hackers forums, part of the PostgreSQL category; --> Is there any plans to create an INSTEAD OF trigger on VIEWS? I have view which consists of a ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 05:02 AM
--= Tono =--
 
Posts: n/a
Default INSTEAD OF trigger on VIEWs

Is there any plans to create an INSTEAD OF trigger on
VIEWS? I have view which consists of a master and
detail table. When a row is inserted into the view,
the view needs to figure out if the master record
already exsists. If the record does not exists in the
master table, then insert into the master and the
detail table. If the record already exists in the
master, just insert into detail table. Conversely, if
a delete record is performed on the view, the view
needs to figure out if it only needs to delete from
the detail table, or should it also delete from the
master table when all the detail records are already
deleted. In Oracle this is easily done using INSTEAD
OF triggers. INSTEAD OF triggers can only be created
for VIEWs. The purpose of it is to "short-circuit" the
event (INSERT, UPDATE or DELETE) and perform whatever
is specified in the trigger.

CREATE OR REPLACE TRIGGER schema.trigger_name INSTEAD
OF INSERT ON object_name
BEGIN
-- Perform the following instead --
END;



__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 05:02 AM
Christopher Kings-Lynne
 
Posts: n/a
Default Re: INSTEAD OF trigger on VIEWs

You can probably just create an INSTEAD rule on the view...

Chris

--= Tono =-- wrote:
> Is there any plans to create an INSTEAD OF trigger on
> VIEWS? I have view which consists of a master and
> detail table. When a row is inserted into the view,
> the view needs to figure out if the master record
> already exsists. If the record does not exists in the
> master table, then insert into the master and the
> detail table. If the record already exists in the
> master, just insert into detail table. Conversely, if
> a delete record is performed on the view, the view
> needs to figure out if it only needs to delete from
> the detail table, or should it also delete from the
> master table when all the detail records are already
> deleted. In Oracle this is easily done using INSTEAD
> OF triggers. INSTEAD OF triggers can only be created
> for VIEWs. The purpose of it is to "short-circuit" the
> event (INSERT, UPDATE or DELETE) and perform whatever
> is specified in the trigger.
>
> CREATE OR REPLACE TRIGGER schema.trigger_name INSTEAD
> OF INSERT ON object_name
> BEGIN
> -- Perform the following instead --
> END;
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 05:02 AM
Jan B.
 
Posts: n/a
Default Re: INSTEAD OF trigger on VIEWs

I have a similar problem and already considered using RULEs, but I
encountered the problem, that I did not find any way to execute
procedures from RULEs without using SELECT, which creates always a
result set being passed to the application invoking the INSERT, UPDATE
or DELETE, even if the function is declared VOID. This is causing
trouble when using asynchronous command processing.

Christopher Kings-Lynne wrote:

> You can probably just create an INSTEAD rule on the view...
>
> Chris
>
> --= Tono =-- wrote:
>
>> Is there any plans to create an INSTEAD OF trigger on
>> VIEWS? I have view which consists of a master and
>> detail table. When a row is inserted into the view,
>> the view needs to figure out if the master record
>> already exsists. If the record does not exists in the
>> master table, then insert into the master and the
>> detail table. If the record already exists in the
>> master, just insert into detail table. Conversely, if
>> a delete record is performed on the view, the view
>> needs to figure out if it only needs to delete from
>> the detail table, or should it also delete from the
>> master table when all the detail records are already
>> deleted. In Oracle this is easily done using INSTEAD
>> OF triggers. INSTEAD OF triggers can only be created
>> for VIEWs. The purpose of it is to "short-circuit" the
>> event (INSERT, UPDATE or DELETE) and perform whatever
>> is specified in the trigger.
>>
>> CREATE OR REPLACE TRIGGER schema.trigger_name INSTEAD
>> OF INSERT ON object_name BEGIN
>> -- Perform the following instead --
>> END;
>>
>>



---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-11-2008, 05:02 AM
Christopher Kings-Lynne
 
Posts: n/a
Default Re: INSTEAD OF trigger on VIEWs

> I have a similar problem and already considered using RULEs, but I
> encountered the problem, that I did not find any way to execute
> procedures from RULEs without using SELECT, which creates always a
> result set being passed to the application invoking the INSERT, UPDATE
> or DELETE, even if the function is declared VOID. This is causing
> trouble when using asynchronous command processing.


The solution then is for us to get around to implementing procedures,
rather than functions, in PostgreSQL I think.

Chris

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-11-2008, 05:02 AM
Jan B.
 
Posts: n/a
Default Re: INSTEAD OF trigger on VIEWs

Christopher Kings-Lynne wrote:

>> I have a similar problem and already considered using RULEs, but I
>> encountered the problem, that I did not find any way to execute
>> procedures from RULEs without using SELECT, which creates always a
>> result set being passed to the application invoking the INSERT,
>> UPDATE or DELETE, even if the function is declared VOID. This is
>> causing trouble when using asynchronous command processing.

>
>
> The solution then is for us to get around to implementing procedures,
> rather than functions, in PostgreSQL I think.
>
> Chris
>

Yes, I think that this would be a good way to solve the problem, but is
it planned to implement procedures in near future?
What about extending the SQL command set by an "INVOKE" command, which
invokes a function and discards the result?

Jan Behrens

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com