pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedA bug in triggers PG 7.1.3 or misunderstand ?
3+ messages / 2 participants
[nested] [flat]
* A bug in triggers PG 7.1.3 or misunderstand ?
@ 2001-09-25 08:34 Domingo Alvarez Duarte <domingo@dad-it.com>
2001-09-27 16:32 ` Re: A bug in triggers PG 7.1.3 or misunderstand ? Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 3+ messages in thread
From: domingo@dad-it.com @ 2001-09-25 08:34 UTC (permalink / raw)
To: pgsql-sql
I have this database and it was working with PG 7.1.2 !!!
When I try to delete a record the trigger is fired but the delete is
not executed.
---------------------------------------code start here
drop database test_trig;
create database test_trig;
\connect test_trig
--
-- TOC Entry ID 2 (OID 81843)
--
-- Name: client_pages_id_seq Type: SEQUENCE Owner: mingo
--
CREATE SEQUENCE "client_pages_id_seq" start 1 increment 1 maxvalue
2147483647 minvalue 1 cache 1 ;
--
-- TOC Entry ID 34 (OID 81862)
--
-- Name: client_pages Type: TABLE Owner: mingo
--
CREATE TABLE "client_pages" (
"id" integer DEFAULT nextval('"client_pages_id_seq"'::text) NOT NULL,
"client_id" integer NOT NULL,
"name" character varying(250) NOT NULL,
"lang_id" integer,
"content" text,
Constraint "client_pages_pkey" Primary Key ("id")
);
--
-- TOC Entry ID 28 (OID 82749)
--
-- Name: client_pages_trash_id_seq Type: SEQUENCE Owner: mingo
--
CREATE SEQUENCE "client_pages_trash_id_seq" start 1 increment 1
maxvalue 2147483647 minvalue 1 cache 1 ;
--
-- TOC Entry ID 66 (OID 82768)
--
-- Name: client_pages_trash Type: TABLE Owner: mingo
--
CREATE TABLE "client_pages_trash" (
"id" integer DEFAULT nextval('"client_pages_trash_id_seq"'::text) NOT
NULL,
"client_id" integer NOT NULL,
"page_id" integer,
"page_name" character varying(250),
"date_posted" timestamp with time zone DEFAULT now(),
"content" text,
Constraint "client_pages_trash_pkey" Primary Key ("id")
);
--
-- TOC Entry ID 85 (OID 82803)
--
-- Name: "client_pages_upd_del_tr" () Type: FUNCTION Owner: mingo
--
CREATE FUNCTION "client_pages_upd_del_tr" () RETURNS opaque AS '
begin
insert into client_pages_trash(client_id,page_id,page_name,content)
values(old.client_id,old.id,old.name,old.content);
return new;
end;' LANGUAGE 'plpgsql';
--
-- TOC Entry ID 112 (OID 93427)
--
-- Name: client_pages_tr Type: TRIGGER Owner: mingo
--
CREATE TRIGGER "client_pages_tr" BEFORE DELETE OR UPDATE ON
"client_pages" FOR EACH ROW EXECUTE PROCEDURE
"client_pages_upd_del_tr" ();
insert into client_pages(client_id,name,lang_id,content)
values(1,'car',1,'hello');
select * from client_pages;
select * from client_pages_trash;
update client_pages set content = 'updated' where id = 1;
select * from client_pages;
select * from client_pages_trash;
delete from client_pages where id = 1;
select * from client_pages;
select * from client_pages_trash;
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: A bug in triggers PG 7.1.3 or misunderstand ?
2001-09-25 08:34 A bug in triggers PG 7.1.3 or misunderstand ? Domingo Alvarez Duarte <domingo@dad-it.com>
@ 2001-09-27 16:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-09-28 08:28 ` Re: A bug in triggers PG 7.1.3 or misunderstand ? Domingo Alvarez Duarte <domingo@dad-it.com>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2001-09-27 16:32 UTC (permalink / raw)
To: domingo@dad-it.com; +Cc: pgsql-sql
I think you need "return old", not "return new", in the body of the
trigger if you want the delete to take place. new would be NULL in
a delete situation ...
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: A bug in triggers PG 7.1.3 or misunderstand ?
2001-09-25 08:34 A bug in triggers PG 7.1.3 or misunderstand ? Domingo Alvarez Duarte <domingo@dad-it.com>
2001-09-27 16:32 ` Re: A bug in triggers PG 7.1.3 or misunderstand ? Tom Lane <tgl@sss.pgh.pa.us>
@ 2001-09-28 08:28 ` Domingo Alvarez Duarte <domingo@dad-it.com>
0 siblings, 0 replies; 3+ messages in thread
From: domingo@dad-it.com @ 2001-09-28 08:28 UTC (permalink / raw)
To: pgsql-sql
tgl@sss.pgh.pa.us (Tom Lane) wrote in message news:<28856.1001608373@sss.pgh.pa.us>...
> I think you need "return old", not "return new", in the body of the
> trigger if you want the delete to take place. new would be NULL in
> a delete situation ...
>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
Ok I saw that in the documentation so I tryied a variant of it:
if TG_OP = 'DELETE' then
return old;
else
return new;
end if;
But the TG_OP comes empty and it allawys try return new preventing the
delete to happen.
And that was supposed to work isn't it ?
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2001-09-28 08:28 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-09-25 08:34 A bug in triggers PG 7.1.3 or misunderstand ? Domingo Alvarez Duarte <domingo@dad-it.com>
2001-09-27 16:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2001-09-28 08:28 ` Domingo Alvarez Duarte <domingo@dad-it.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox