Re: trigger errors

From: Ron Peterson <rpeterson(at)yellowbank(dot)com>
To: Marc Britten <mbritten(at)cybernet-usa(dot)com>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: trigger errors
Date: 2000-06-15 15:32:52
Message-ID: 3948F724.7459DB56@yellowbank.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Marc Britten wrote:
>
> hi again,
>
> i created a trigger on a table for insert or delete, and a function that
> gets created fine.
>
> however when i go to insert something into the table i get
>
> NOTICE: plpgsql: ERROR during compile of create_count_cache near line 2
> ERROR: parse error at or near ";"

Hi Marc,

Try this function instead:

CREATE FUNCTION create_count_cache()
RETURNS opaque AS '
BEGIN
DELETE FROM LangCount;
INSERT INTO LangCount
SELECT LangID as ID, COUNT(LangID) AS CNT
FROM snippet
GROUP BY LangID;
DELETE FROM CatCount;
INSERT INTO CatCount
SELECT LangID as ID, COUNT(LangID) AS CNT
FROM snippet
GROUP BY LangID;
RETURN NEW;
END;'
LANGUAGE 'plpgsql';

There are two changes from what you have. You cannot use BEGIN/COMMIT
(i.e. transactions) within a function or trigger. In plpgsql, use BEGIN
and END to delimit your function statements. There is more information
about this in the PL/pgSQL portion of the user's guide. The function
also needs to return something. A return type of 'opaque' doesn't mean
the function returns nothing, it means the function doesn't return a
defined SQL datatype.

________________________
Ron Peterson
rpeterson(at)yellowbank(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron Peterson 2000-06-15 16:00:53 Re:
Previous Message Patrick FICHE 2000-06-15 14:02:19 Performance for indexes on functions