Re: assigning result of SELECT in TRIGGER

From: "Jeff Eckermann" <jeckermann(at)verio(dot)net>
To: "Randall Perry" <rgp(at)systame(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: assigning result of SELECT in TRIGGER
Date: 2001-08-17 14:25:58
Message-ID: 00d101c12728$8900f140$279c10ac@INTERNAL
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Plpgsql is getting confused by the double usage of the name "status", i.e.
as a variable, and as the name of a field.
Choosing a different name for your variable should work.
I think the usual syntax for this kind of operation is:
SELECT field INTO variable FROM....
I don't see why your construction wouldn't work, though.
Anyone want to comment on whether this makes a difference, and why?
----- Original Message -----
From: "Randall Perry" <rgp(at)systame(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Sent: Thursday, August 16, 2001 9:01 PM
Subject: [GENERAL] assigning result of SELECT in TRIGGER

> Upon inserting a record into the confirm table I get this error in psql:
>
> ERROR: parser: parse error at or near "SELECT"
>
> What am I doing wrong. Is there a proper way to get a value from a related
> table.
>
>
>
> The function and trigger defs are:
>
> CREATE FUNCTION chk_status () RETURNS OPAQUE AS '
> DECLARE
> status BOOLEAN;
> BEGIN
> status := SELECT status FROM log WHERE log.log_no = NEW.log_no;
> IF NOT status THEN
> RAISE EXCEPTION ''The log entry you are trying to confirm
> was not successfully forwarded and does not need confirmation'';
> END IF;
> END;
> ' LANGUAGE 'plpgsql';
>
>
> CREATE TRIGGER chk_status BEFORE INSERT ON confirm FOR EACH ROW EXECUTE
> PROCEDURE chk_status();
>
> --
> Randy Perry
> sysTame
> Mac Consulting/Sales
>
> phn 561.589.6449
> mobile email help(at)systame(dot)com
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-08-17 14:33:15 Re: permissions question
Previous Message Tom Lane 2001-08-17 14:18:43 Re: slow update but have an index