BEGIN EXCEPTION END - small bug?

From: Daniel Schuchardt <daniel_schuchardt(at)web(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Subject: BEGIN EXCEPTION END - small bug?
Date: 2004-08-11 12:20:34
Message-ID: cfd2uf$21qq$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi list,

i tried a bit with errorhandling and found the following :
(i want to ignore the dublicate key exception)

CREATE OR REPLACE FUNCTION test() RETURNS VARCHAR AS'
BEGIN
BEGIN
INSERT INTO table a dublicate key (primary);
EXCEPTION
WHEN OTHERS THEN ROLLBACK;
END;
RETURN ''test'';
END'LANGUAGE plpgsql;

will result in

ERROR: SPI_prepare failed for "ROLLBACK": SPI_ERROR_TRANSACTION

I noticed the right syntax would be (works fine)

CREATE OR REPLACE FUNCTION test() RETURNS VARCHAR AS'
BEGIN
BEGIN
INSERT INTO table a dublicate key (primary);
EXCEPTION
WHEN OTHERS THEN
END;
RETURN ''test'';
END'LANGUAGE plpgsql;

Just a hint

Regards Daniel

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andreas Pflug 2004-08-11 13:07:09 libpq problem
Previous Message Andrew Dunstan 2004-08-11 12:06:07 Re: Missing French backend translations in the HEAD