Error message with COMMIT/ROLLBACK within PL/pgSQL

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Error message with COMMIT/ROLLBACK within PL/pgSQL
Date: 2010-10-28 10:47:28
Message-ID: 4CC954C0.40106@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

This is not very user-friendly:

postgres=# do $$
begin
COMMIT;
end;
$$;
ERROR: SPI_execute_plan_with_paramlist failed executing query "COMMIT":
SPI_ERROR_TRANSACTION
CONTEXT: PL/pgSQL function "inline_code_block" line 2 at SQL statement

Clearly we don't support that, but seems like it would deserve a better
error message.

Curiously, we *do* give a better error message if you try that with EXECUTE:

postgres=# do $$
begin
EXECUTE 'COMMIT';
end;
$$;
ERROR: cannot begin/end transactions in PL/pgSQL
HINT: Use a BEGIN block with an EXCEPTION clause instead.
CONTEXT: PL/pgSQL function "inline_code_block" line 2 at EXECUTE statement

Barring objections, I'll add the same error message to the non-execute
codepath.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

Attachment Content-Type Size
commit-in-plpgsql-errmsg-1.patch text/x-diff 870 bytes

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Golub 2010-10-28 10:49:48 Re: add label to enum syntax
Previous Message Boszormenyi Zoltan 2010-10-28 09:40:28 Re: plan time of MASSIVE partitioning ...