Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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: commit-in-plpgsql-errmsg-1.patch
Description: text/x-diff (870 bytes)

pgsql-hackers by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group