From: | "Chris Halsberghe" <cehals(at)hotmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Creating/Using functions in pl/pgsql |
Date: | 2001-11-15 14:11:03 |
Message-ID: | F124s4PJ5aAJAFXQWAz00004f5a@hotmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
When trying to define a trigger and a function (mail_notify) on a
certain table, I received an error notification which I couldn't understand:
<quote>
NOTICE: plpgsql: ERROR during compile of mail_notify near line 1
ERROR: parse error at or near "
</quote>
I could not see any syntax error in the definition of the function, which
was accepted by the postmaster
at creation time without complaints.
Then I tried to code the example from the Programmer's Manual, Chapter 24
Here is the text for that example:
<quote>
Example 24-1. A PL/pgSQL Trigger Procedure Example
This trigger ensures, that any time a row is inserted or updated in the
table, the current user name and
time are stamped into the row. And it ensures that an employees name is
given and that the salary is a
positive value.
CREATE TABLE emp (
empname text,
salary integer,
last_date timestamp,
last_user text
);
CREATE FUNCTION emp_stamp () RETURNS OPAQUE AS ’
BEGIN
-- Check that empname and salary are given
IF NEW.empname ISNULL THEN
RAISE EXCEPTION ’’empname cannot be NULL value’’;
END IF;
IF NEW.salary ISNULL THEN
RAISE EXCEPTION ’’% cannot have NULL salary’’,
NEW.empname;
END IF;
-- Who works for us when she must pay for?
IF NEW.salary < 0 THEN
RAISE EXCEPTION ’’% cannot have a negative salary’’,
NEW.empname;
END IF;
-- Remember who changed the payroll when
NEW.last_date := ’’now’’;
NEW.last_user := current_user;
RETURN NEW;
END;
’ LANGUAGE ’plpgsql’;
CREATE TRIGGER emp_stamp BEFORE INSERT OR UPDATE ON emp
FOR EACH ROW EXECUTE PROCEDURE emp_stamp();
</quote>
I get exactly the same kind of error message from the postmaster:
<quote>
NOTICE: plpgsql: ERROR during compile of emp_stamp near line 1
ERROR: parse error at or near "
</quote>
What is the explanation of this behaviour?
Chris
_________________________________________________________________
Download MSN Explorer gratis van http://explorer.msn.nl/intl.asp
From | Date | Subject | |
---|---|---|---|
Next Message | Calin Lukas | 2001-11-15 14:18:36 | Ann: Database Developing and Reporting System |
Previous Message | tony | 2001-11-15 14:07:40 | Re: Ultradev and PostgreSQL on SuSE |