Re: Bug in triggers - Mailing list pgsql-bugs

From Oleg Serov
Subject Re: Bug in triggers
Date
Msg-id cec7c6df1002260631x214a0addi1fc6296aaed43860@mail.gmail.com
Whole thread Raw
In response to Re: Bug in triggers  ("Oleg Serov" <serovov@gmail.com>)
Responses Re: Bug in triggers
List pgsql-bugs
Up!, Anybody will answer on this bugreport?

On Fri, Sep 26, 2008 at 2:57 PM, Oleg Serov <serovov@gmail.com> wrote:

> Sorry, bug is not in triggers, it is in PL/PGSQL  var assign mechanism
> here it is an example:
> ROLLBACK;
> BEGIN;
>
> CREATE TYPE "composite_type" AS (
>         "type" VARCHAR,
>        "type2" VARCHAR
> );
>
>
> CREATE TABLE "buggy" (
>        "id" BIGINT NOT NULL,
>        "bug" "composite_type",
>        CONSTRAINT "buggy_pkey" PRIMARY KEY("id")
> ) WITH OIDS;
>
>
> CREATE OR REPLACE FUNCTION "test_bug" () RETURNS pg_catalog.void AS
> $body$
> DECLARE
>    tmp_old buggy%rowtype;
> BEGIN
>        tmp_old :=3D ROW(1, NULL)::buggy;
>        IF tmp_old::text <> ROW(1, NULL)::buggy::text THEN
>                RAISE EXCEPTION '% <> %', tmp_old, ROW(1, NULL)::buggy;
>        END IF;
> END;
> $body$
> LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
>
> WILL THROW A EXCEPTION:
> ERROR:  (1,"(,)") <> (1,)
>
>
> SELECT test_bug();
>
>
> 2008/9/26, Oleg Serov <serovov@gmail.com>:
> > SQL code:
> >
> >
> > ROLLBACK;
> > BEGIN;
> > CREATE TYPE "composite_type" AS (
> >     "typename" VARCHAR
> > );
> >
> >
> > CREATE TABLE "buggy" (
> >     "id" BIGINT NOT NULL,
> >     "bug" "composite_type",
> >     CONSTRAINT "buggy_pkey" PRIMARY KEY("id")
> > ) WITH OIDS;
> >
> > INSERT INTO buggy (id, bug) VALUES
> >     (100196418052926086, NULL);
> >
> > CREATE OR REPLACE FUNCTION "public"."test_bug" () RETURNS trigger AS
> > $body$
> > DECLARE
> >     tmp_old buggy%rowtype;
> >     tmp_new buggy%rowtype;
> > BEGIN
> >     RAISE NOTICE 'OLD: %', OLD;
> >     RAISE NOTICE 'NEW: %', NEW;
> >
> >         tmp_old :=3D OLD;
> >         RAISE NOTICE 'TMP OLD: %', tmp_old;
> >
> >     RAISE NOTICE 'TMP OLD =3D OLD =3D> %', tmp_old::text =3D OLD::text;
> >
> >         tmp_old.id :=3D NEW.id;
> >         tmp_new :=3D NEW;
> >
> >     RAISE NOTICE 'TMP OLD: %', tmp_old;
> >     RAISE NOTICE 'TMP NEW: %', tmp_new;
> >
> >     RAISE NOTICE 'TMP OLD =3D TMP NEW =3D> %', tmp_old::text =3D tmp_ne=
w::text;
> >     RAISE NOTICE 'TMP OLD =3D NEW =3D> %', tmp_old::text =3D NEW::text;
> >
> >
> >
> >         IF (tmp_old::text <> tmp_new::text) <> (tmp_old::text <>
> NEW::text)
> > THEN
> >             RAISE EXCEPTION 'PGSQL BUG!';
> >         END IF;
> >     RETURN OLD;
> > END;
> > $body$
> > LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
> >
> > CREATE TRIGGER "t_bug" BEFORE UPDATE
> > ON buggy FOR EACH ROW
> > EXECUTE PROCEDURE "test_bug"();
> >
> >
> > UPDATE buggy SET id =3D  100112779830304388  WHERE  100196418052926086 =
 =3D
> id;
> > /**
> > NOTICE:  OLD: (100196418052926086,)
> > NOTICE:  NEW: (100112779830304388,)
> > NOTICE:  TMP OLD: (100196418052926086,"()")
> > NOTICE:  TMP OLD =3D OLD =3D> f
> > NOTICE:  TMP OLD: (100112779830304388,"()")
> > NOTICE:  TMP NEW: (100112779830304388,"()")
> > NOTICE:  TMP OLD =3D TMP NEW =3D> t
> > NOTICE:  TMP OLD =3D NEW =3D> f -- BUG!!!
> >
> > **/
> >
>



--=20
=F3 =D5=D7=C1=D6=C5=CE=C9=C5=CD

=EF=CC=C5=C7 =F3=C5=D2=CF=D7

pgsql-bugs by date:

Previous
From: Oleg Serov
Date:
Subject: Re: Bug in procedure When you modificate table
Next
From: Oleg Serov
Date:
Subject: Re: Bug in PL/PgSQL "SELECT .. INTO" statement parser