Re: not logging caught exceptions

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: not logging caught exceptions
Date: 2009-11-12 13:57:34
Message-ID: 1258034254.26305.29.camel@fsopti579.F-Secure.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On ons, 2009-11-11 at 19:45 -0500, Tom Lane wrote:
> > try
> > insert
> > catch unique_constraint_violation
> > update
> > end try
>
> > this will end up cluttering the logs with all the constraint violation
> > messages.
>
> Really? It's not supposed to.

There might be a different bug here. This doesn't look right:

CREATE LANGUAGE plpgsql;

CREATE TABLE keytest (a int PRIMARY KEY, b text);

CREATE OR REPLACE FUNCTION insert_or_update(new_a int, new_b text)
RETURNS text
LANGUAGE plpgsql
AS $$
BEGIN
INSERT INTO keytest VALUES (new_a, new_b);
RETURN 'inserted';
EXCEPTION
WHEN integrity_constraint_violation THEN
UPDATE keytest SET a = new_a, b = new_b;
RETURN 'updated';
END;
$$;

SELECT insert_or_update(1, 'one');
SELECT insert_or_update(1, 'one');
SELECT insert_or_update(2, 'two');
SELECT insert_or_update(2, 'two');

Results in:

insert_or_update
------------------
inserted
(1 row)

insert_or_update
------------------
updated
(1 row)

insert_or_update
------------------
inserted
(1 row)

ERROR: duplicate key value violates unique constraint "keytest_pkey"
CONTEXT: SQL statement "UPDATE keytest SET a = $1 , b = $2 "
PL/pgSQL function "insert_or_update" line 6 at SQL statement

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Merlin Moncure 2009-11-12 14:30:48 Re: Listen / Notify rewrite
Previous Message Andrew Chernow 2009-11-12 13:25:27 Re: Listen / Notify rewrite