This will be possible with PostgreSQL 9.1, but I don't think there is any way doing that without defining cascading constraints developer.postgresql.org/pgdocs/postgres....
This will be possible with PostgreSQL 9.1, but I don't think there is any way doing that without defining cascading constraints. developer.postgresql.org/pgdocs/postgres....
1 Ouch! Are you talking about something along the lines of 'ON UPDATE CASCADE ON DELETE CASCADE' on the foreign key? Developer.postgresql.Org currently not working for me... – Jonas Byström Apr 15 at 12:28 @Jonas: yes the ON DELETE CASCADE is s what I'm talking about – a_horse_with_no_name Apr 15 at 12:31.
You can wait for 9.1 or create a set-returning function meanwhile: CREATE OR REPLACE FUNCTION fn_delete_btable(params) RETURNS SETOF btable. Aid%TYPE AS $$ DELETE FROM btable WHERE expression_over_params(params) RETURNING aid $$ LANGUAGE 'sql'; DELETE FROM atable WHERE aid IN ( SELECT aid FROM fn_delete_btable(params) ) P.S. Just in case if you're not aware about standard SQL way of doing it. If you create the tables like this: CREATE TABLE btable (aid INT NOT NULL UNIQUE, …) CREATE TABLE atable (aid INT NOT NULL FOREIGN KEY REFERENCES (aid) ON DELETE CASCADE, …) then a delete from btable will trigger a delete from atable as well.
For this to work, btable. Aid should be UNIQUE or a PRIMARY KEY, and this is less efficient for mass updates than a set-based solution.
Nice idea about the function returning the ids – a_horse_with_no_name Apr 15 at 12:31.
You should be able to do that: here is an example that I found on the bottom of this page. CREATE TABLE order_items ( product_no integer REFERENCES products ON DELETE RESTRICT, order_id integer REFERENCES orders ON DELETE CASCADE, quantity integer, PRIMARY KEY (product_no, order_id) ).
DB functions are outside my comfort zone (I know, I know) and I didn't want to make even temporary changes to the columns in question so I simply did a CREATE TABLE CTable AS ... expression that depends on BTAble ...; and used that to sequentially delete data in B and A.
1: I know, I know, but it's far from the best answer. – onedaywhen Apr 19 at 10:40 You're probably right in the general case. For me this was the simplest solution to my problem.
– Jonas Byström Apr 20 at 8:22.
P.S. Just in case if you're not aware about standard SQL way of doing it. Then a delete from btable will trigger a delete from atable as well. For this to work, btable.
Aid should be UNIQUE or a PRIMARY KEY, and this is less efficient for mass updates than a set-based solution.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.