From: | "Rajesh Kumar Mallah(dot)" <mallah(at)trade-india(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Cascading deletions does not seem to work inside PL/PGSQL functions. |
Date: | 2002-07-16 11:25:14 |
Message-ID: | 200207161655.14794.mallah@trade-india.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi folks,
This problem has been troubling me for quite sometime and
I would be very thankful for your help.
I have included the complete commented script to recreate the problem in
question.
The problem is inside a plpgsql function i do not see the records in the slave tables
getting deleted when i delete the corresponing referenced record from the master table.
But things as expected inside a Transaction at the PSQL prompt.
any help is very much appreciated.
regds
mallah.
-------------------- stuff in test_case.sql -----------------------
-- W A R N I N G
--- scripts will delete tables t_master and t_slave and a function t_test()
---
DROP TABLE t_master; --clean up stuff first.
DROP TABLE t_slave;
CREATE TABLE t_master (id integer primary key);
CREATE TABLE t_slave (id integer references t_master
on delete cascade
on update cascade unique
);
INSERT INTO t_master values (1);
INSERT INTO t_slave values (1);
-- Demonstrate that record in salve table do get
-- deleted when the master record is deleted.
BEGIN work;
delete from t_master where id=1;
select id from t_slave where id=1; -- <-- this selects returns no record.
ROLLBACK;
-- Same stuff tried inside a PL/PGSQL function...
DROP FUNCTION t_test();
CREATE OR REPLACE FUNCTION t_test () RETURNS integer AS '
DECLARE rec RECORD;
BEGIN
DELETE FROM t_master where id=1;
SELECT INTO rec id from t_slave where id=1; -- <-- this selects returns record.
RAISE NOTICE ''id in slave table is %'' , rec.id ;
RETURN 1;
END;
' LANGUAGE 'plpgsql' ;
select t_test();
--------------------------- the end -----------------------------------
--
Rajesh Kumar Mallah,
Project Manager (Development)
Infocom Network Limited, New Delhi
phone: +91(11)6152172 (221) (L) ,9811255597 (M)
Visit http://www.trade-india.com ,
India's Leading B2B eMarketplace.
Attachment | Content-Type | Size |
---|---|---|
test_case.sql | text/x-diff | 1.0 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Rajesh Kumar Mallah. | 2002-07-16 11:34:24 | Re: How do I concatenate row-wise instead of column-wise? |
Previous Message | Richard Huxton | 2002-07-16 09:15:51 | Re: How do I concatenate row-wise instead of column-wise? |