From: Riccardo G. Facchini <abief_ag_-postgresql@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: transactions in functions, possible bug or what I'm doing wrong?
Date: Fri, 19 Nov 2004 03:52:31 -0800 (PST)
Message-ID: <20041119115231.27648.qmail@web13924.mail.yahoo.com> (raw)
Hi All,
PostgreSQL 7.4.5
assume this script:
---
create table test_table
(
id serial,
test_value text
) without oids;
insert into test_table
(test_value)
values ('A');
insert into test_table
(test_value)
values ('B');
insert into test_table
(test_value)
values ('C');
insert into test_table
(test_value)
values ('D');
CREATE OR REPLACE FUNCTION test_with_transaction()
RETURNS text AS
'declare my_test_record record;
declare my_return_value text;
begin
my_return_value := '''';
start transaction;
for my_test_record in select * from test_table
loop
my_return_value := my_return_value || my_test_record.test_value;
end loop;
return my_return_value;
commit;
end;'
LANGUAGE 'plpgsql' VOLATILE;
CREATE OR REPLACE FUNCTION test_without_transaction()
RETURNS text AS
'declare my_test_record record;
declare my_return_value text;
begin
my_return_value := '''';
for my_test_record in select * from test_table
loop
my_return_value := my_return_value || my_test_record.test_value;
end loop;
return my_return_value;
end;'
LANGUAGE 'plpgsql' VOLATILE;
---
Why does select test_without_transaction();
return this info:
"ABCD" (as should be)
and select test_with_transaction();
returns this error?
ERROR: SPI_prepare() failed on "start transaction"
CONTEXT: PL/pgSQL function "test_with_transaction" line 6 at SQL
statement
I've been investigating the matter in the doc I have, but to no avail.
google was not helpful either.
any suggestion? is this a bug? or the bug resides in my head?
regards,
Riccardo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: abief_ag_-postgresql@yahoo.com
Subject: Re: transactions in functions, possible bug or what I'm doing wrong?
In-Reply-To: <20041119115231.27648.qmail@web13924.mail.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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