Re: No return from trigger function

From: "James B(dot) Byrne" <byrnejb(at)harte-lyne(dot)ca>
To: depesz(at)depesz(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: No return from trigger function
Date: 2009-04-08 20:13:58
Message-ID: 41258.216.185.71.24.1239221638.squirrel@webmail.harte-lyne.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Wed, April 8, 2009 16:05, hubert depesz lubaczewski wrote:
> On Wed, Apr 08, 2009 at 03:59:22PM -0400, James B. Byrne wrote:
>> EXCEPTION
>> WHEN unique_violation THEN
>> -- NULL -- do nothing
>>
>> RETURN NULL; -- AFTER trigger results are ignored anyway
>> END;
>
> exception is part of begin/exception/end; block
> so you will need one more begin and one more end;
>

Does this mean that the example given on pg. 798 of the manual is in
error, or have I misread it?

-- Insert or update the summary row with the new values.
<<insert_update>>
LOOP
UPDATE sales_summary_bytime
SET amount_sold = amount_sold + delta_amount_sold,
units_sold = units_sold + delta_units_sold,
amount_cost = amount_cost + delta_amount_cost
WHERE time_key = delta_time_key;
EXIT insert_update WHEN found;
BEGIN
INSERT INTO sales_summary_bytime (
time_key,
amount_sold,
units_sold,
amount_cost)
VALUES (
delta_time_key,
delta_amount_sold,
delta_units_sold,
delta_amount_cost
);
EXIT insert_update;
EXCEPTION
WHEN UNIQUE_VIOLATION THEN
-- do nothing
END;
END LOOP insert_update;
RETURN NULL;
END;

--
*** E-Mail is NOT a SECURE channel ***
James B. Byrne mailto:ByrneJB(at)Harte-Lyne(dot)ca
Harte & Lyne Limited http://www.harte-lyne.ca
9 Brockley Drive vox: +1 905 561 1241
Hamilton, Ontario fax: +1 905 561 0757
Canada L8E 3C3

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2009-04-08 20:16:55 Re: No return from trigger function
Previous Message Guillaume Lelarge 2009-04-08 20:10:03 Re: No return from trigger function