error when executing dynamic commands with transaction - Mailing list pgsql-general

From Pascal Polleunus
Subject error when executing dynamic commands with transaction
Date
Msg-id 402B553C.2020908@beeznest.net
Whole thread Raw
Responses Re: error when executing dynamic commands with transaction  (Shridhar Daithankar <shridhar@frodo.hserus.net>)
List pgsql-general
(another try with a different subject as it doesn't seem to work with
"EXECUTE + transaction = unexpected error -8" :-/)


Hi,

It seems that there is a problem when executing a dynamic commands
containing a transaction...

Here's a simple example...

CREATE OR REPLACE FUNCTION fct_trig2()
RETURNS TRIGGER AS '
BEGIN
   EXECUTE ''BEGIN;''
     || ''CREATE TABLE t2_'' || NEW.id::TEXT || ''(''
     || ''  CONSTRAINT pkt2_'' || NEW.id::TEXT || '' PRIMARY KEY (id)''
     || '') INHERITS (t1);''
     || ''COMMIT;'';
   RETURN NEW;
END;'
LANGUAGE 'plpgsql';

CREATE TABLE t1 (id INT PRIMARY KEY);

CREATE TABLE t2 (id INT PRIMARY KEY);
CREATE TRIGGER trig2 AFTER INSERT ON t2 FOR EACH ROW EXECUTE PROCEDURE
fct_trig2();

test=# INSERT INTO t2 VALUES (1);
ERROR:  unexpected error -8 in EXECUTE of query "BEGIN;CREATE TABLE
t2_1( CONSTRAINT pkt2_1 PRIMARY KEY (id)) INHERITS (t1);COMMIT;"
CONTEXT:  PL/pgSQL function "fct_trig2" line 2 at execute statement


If I don't use a transaction in the executed statement, there is no problem.
Remark: In this example a transaction is not needed, but in my real
usage of this I'm creating a table and granting permissions, and maybe
also creating a view. So a transaction is preferable.

I've tested this on "PostgreSQL 7.4.1 on i386-pc-linux-gnu, compiled by
GCC i386-linux-gcc (GCC) 3.3.2 (Debian)", Debian Sarge.

And also on "PostgreSQL 7.2.1 on i686-pc-linux-gnu, compiled by GCC
2.95.4", Debian Woody.
On that system, the function fct_trig2() needs to return OPAQUE instead
of TRIGGER.


Thanks,
Pascal



pgsql-general by date:

Previous
From: "Cyril VELTER"
Date:
Subject: Re: Prepared queries
Next
From: "C G"
Date:
Subject: Re: pl/pythonu