473,416 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

View's rule on delete problem


CREATE RULE "new_rule2" AS ON DELETE TO "public"."klients_view"
DO INSTEAD (

DELETE
FROM klients
WHERE (klients.klient_id = old.klient_id);

DELETE
FROM klient_services
WHERE (klient_services.klient_id = old.klient_id);
);

It's 2 commands, but executing only first. Why?

Stanislaw Tristan
Kyiv, Ukraine
E-mail: st******@i.com.ua
Nov 23 '05 #1
4 3969
"Stanislaw Tristan" <st******@i.com.ua> writes:
It's 2 commands, but executing only first. Why?


You didn't show us the view, but I suppose it's an inner join of the two
tables? As soon as you delete the row from the first table, there's no
longer any matching row in the view, so the second command finds no OLD
row to join against.

Consider making the view a LEFT JOIN and being sure to delete from the
righthand table first.

regards, tom lane

---------------------------(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

Nov 23 '05 #2
On Thu, Oct 28, 2004 at 04:32:21AM +0300, Stanislaw Tristan wrote:

CREATE RULE "new_rule2" AS ON DELETE TO "public"."klients_view"
DO INSTEAD (

DELETE
FROM klients
WHERE (klients.klient_id = old.klient_id);

DELETE
FROM klient_services
WHERE (klient_services.klient_id = old.klient_id);
);

It's 2 commands, but executing only first. Why?


Tom Lane described the problem in another thread a few years ago:

http://archives.postgresql.org/pgsql...6/msg00559.php

"...OLD is essentially a macro for the view. As soon as you delete
a row from foo, there's no longer any such row in the view, so the
delete from bar doesn't find anything to delete."

"What you probably want instead is to make bar reference foo as a
foreign key with ON DELETE CASCADE; then the rule for foobar only
needs to delete from foo explicitly, and the additional delete from
bar is done implicitly by the foreign key trigger."

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #3
"Stanislaw Tristan" <st******@i.com.ua> writes:
It's 2 commands, but executing only first. Why?


You didn't show us the view, but I suppose it's an inner join of the two
tables? As soon as you delete the row from the first table, there's no
longer any matching row in the view, so the second command finds no OLD
row to join against.

Consider making the view a LEFT JOIN and being sure to delete from the
righthand table first.

regards, tom lane

---------------------------(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

Nov 23 '05 #4
On Thu, Oct 28, 2004 at 04:32:21AM +0300, Stanislaw Tristan wrote:

CREATE RULE "new_rule2" AS ON DELETE TO "public"."klients_view"
DO INSTEAD (

DELETE
FROM klients
WHERE (klients.klient_id = old.klient_id);

DELETE
FROM klient_services
WHERE (klient_services.klient_id = old.klient_id);
);

It's 2 commands, but executing only first. Why?


Tom Lane described the problem in another thread a few years ago:

http://archives.postgresql.org/pgsql...6/msg00559.php

"...OLD is essentially a macro for the view. As soon as you delete
a row from foo, there's no longer any such row in the view, so the
delete from bar doesn't find anything to delete."

"What you probably want instead is to make bar reference foo as a
foreign key with ON DELETE CASCADE; then the rule for foobar only
needs to delete from foo explicitly, and the additional delete from
bar is done implicitly by the foreign key trigger."

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: den ryko via .NET 247 | last post by:
Hello to all. Please let me know how to define grid view. When I put following code in to the application file the error ?Type 'GridView' is not defined? persists all the time. Please help me ...
2
by: Joe Del Medico | last post by:
I have two tables A & B and I want to delete all the records in A that are not in B. Can I do this in the query builder? It seems like a simple problem. I can easily find the records in A that...
0
by: Shark | last post by:
Just a post for anyone else that is having this problem (as I've now discovered the solution). The problem is where when looking in the dialog resource view of an MFC project in Visual Studio...
1
by: Berrywong | last post by:
I creat a view in MyDlg using m_pview=new MyView(); I am not sure where I should delete m_pview. I called destroywindow in MyView and MyDlg, I have tried to delete m_pview in destructor of...
4
by: Daniel | last post by:
Hi All, I have question regarding to the read, and update the row in the table. for example: user A, read the row of data from the table. user B, read the row of data from the table as well....
0
by: Santosh | last post by:
Dear all i am downloading MS tree view control . i want to change the font size and font name of the tree view control i am wrtitting code for it like if (!Page.IsPostBack) {...
0
by: Terry | last post by:
In short, I'm getting an IOException "Directory is not empty" if I have a Windows Explorer window open and have a subdirectory selected in the tree view. For example, I have a directory path of...
2
by: D Biegert | last post by:
While in Forms View, a coworker inadvertantly selected Records/Data Entry and it set her form back at record #1 and erased all data from Form View. She still has access to the data in the Datasheet...
0
by: vaskarbasak | last post by:
Hi All, we have a large table having 60 lakhs and more data.so we are facing a problem when we are executing insert or update query. as a result our DB is very slow and sometimes we are facing...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.