![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
CREATE OR REPLACE RULE r_v_songs_upd AS ON UPDATE TO v_songs DO INSTEAD ( UPDATE t_songs SET show = FALSE WHERE NEW.song_id = song_id ; INSERT INTO t_songs ( song_title, year_of_composition, year_of_first_publication, predecessor_id ) VALUES ( NEW.song_title, NEW.year_of_composition, NEW.year_of_first_publication, NEW.song_id ) ) ; If I do the update on v_songs, the update part of the rule gets executed fine, but the insert does not seem to do anything. |
|
An update now results in: psql:data.pgsql:124: ERROR: Cannot update a view You need an unconditional ON UPDATE DO INSTEAD rule Why? |
#3
| |||
| |||
|
|
The above looks like a dead end to me; you can't make it work, and the reason is that OLD and NEW are defined with reference to the view. Once you do the UPDATE, that row is no longer visible in the view (correct?) and so there is no NEW row and the INSERT doesn't do anything. Thats right, I didn't take this into account assuming that NEW and OLD woul= d=20 be unchangeable for the execution of the rule. Then again, why does PostgrS= QL=20 not complain about not being able to insert null (NEW.song_id) into song_id= =20 (this is the pimary key of t_songs)? |
|
Or if not, I think it ought to complain that NEW.* is n= ot=20 valid any longer. |
|
Would it be a great loss to depracate rules? |
#4
| |||
| |||
|
|
It's not trying to insert a row of nulls; it's simply not inserting any row at all. The transformed rule query looks like INSERT INTO t_songs SELECT ... FROM v_songs WHERE ... and the WHERE condition is such that no rows will be selected. |
|
Would it be a great loss to depracate rules? The fact they don't do what you want doesn't make them worthless ... |
|
There is some discussion of rules vs triggers in the docs: http://www.postgresql.org/docs/7.4/s...-triggers.html |
#5
| |||
| |||
|
|
However, the doument of your link below quite clearly states the differences, quite what I needed and was not able to find in the documentation (of 7.3 but it is there too). Looking at the chapter it is supposed to be in some chapter 13.7. However, looking in the index (7.3 interactive) there is only one chapter 13 and that's regression test without a subchapter 7. |
#6
| |||
| |||
|
|
Thiemo Kellner <thiemo (AT) thiam (DOT) ch> writes: However, the doument of your link below quite clearly states the differences, quite what I needed and was not able to find in the documentation (of 7.3 but it is there too). Looking at the chapter it is supposed to be in some chapter 13.7. However, looking in the index (7.3 interactive) there is only one chapter 13 and that's regression test without a subchapter 7. I think you're assuming that 7.3 section numbers would apply to 7.4, which they don't (the html page names are somewhat more likely to carry across, though). |
|
In 7.3 and before the situation is even more confusing because the docs are made up of several separate "books" each with its own chapter numbering. "Rules vs. Triggers" is section 13.7 of the Programmer's Guide book (in 7.3 anyway), whereas you seem to have been seeking it in the Administrator's Guide. |
|
7.4 has just one chapter numbering sequence for the entire SGML document set, which I think is a considerable improvement. We're not going to be revisiting the 7.3 documentation though. My advice: update to 7.4 ;-) |
#7
| |||
| |||
|
#8
| |||
| |||
|
#9
| |||
| |||
|
|
Once again, i´m running into some dificulty with postgres, i need to know if it possible to encrypt and compile, objects such as functions, and triggers so that other users can execute it without seing the code it self, if so could you point me in the right diretion. In SQL server 2000, i would achieve this using WITH ENCRYPTION command, any help is very much apreciated, thanks, |
![]() |
| Thread Tools | |
| Display Modes | |
| |