Re: error in simple sql function breaks connection

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: PostgreSQL Bugs List <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: error in simple sql function breaks connection
Date: 2004-09-06 18:12:47
Message-ID: 17610.1094494367@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr> writes:
> psql> CREATE FUNCTION add_data(TEXT) RETURNS boolean LANGUAGE SQL AS
> 'BEGIN; INSERT INTO foo(data) VALUES($1); COMMIT; SELECT TRUE;';

> psql> SELECT add_data('hello');
> FATAL: EndTransactionBlock: unexpected state BEGIN
> CONTEXT: SQL function "add_data" statement 3
> server closed the connection unexpectedly

> Although the "BEGIN" might not be welcome (well, it was ok, possibly
> ignored, with version 7.4),

I'm surprised the COMMIT didn't dump core on you in older versions.
This could never have worked, because if it actually did try to COMMIT
then the function's execution context would have been yanked out from
underneath it.

Anyway, now it says

regression=# SELECT add_data('hello');
ERROR: cannot begin/end transactions in SQL functions
CONTEXT: SQL function "add_data" statement 1

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PostgreSQL Bugs List 2004-09-06 18:42:25 BUG #1241: returns different result for the same result with differnt plans.
Previous Message Tom Lane 2004-09-06 18:00:24 Re: transaction block: server closed the connection unexpectedly