From: | JanWieck(at)t-online(dot)de (Jan Wieck) |
---|---|
To: | Ed Loehr <eloehr(at)austin(dot)rr(dot)com> |
Cc: | pggeneral <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: PL/pgSQL: "record not assigned yet" meaning? |
Date: | 2000-05-01 21:30:57 |
Message-ID: | 200005012130.XAA08359@hot.jw.home |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Ed Loehr wrote:
> I have a plpgsql function that sets a column value on insert if it was not
> supplied:
>
> CREATE FUNCTION set_expense_unit()
> RETURNS OPAQUE AS
> 'DECLARE
> t RECORD;
> BEGIN
> if NEW.expense_unit_id isnull then
> SELECT INTO t eu.*
> FROM expense_unit eu, expense_type et
> WHERE et.id = NEW.expense_type_id
> AND et.expense_unit_id = eu.id;
>
> NEW.expense_unit_id := t.id;
> end if;
>
> RETURN NEW;
> END;'
> LANGUAGE 'plpgsql';
>
> DROP TRIGGER expense_insert_trigger ON expense;
> CREATE TRIGGER expense_insert_trigger
> BEFORE INSERT ON expense
> FOR EACH ROW
> EXECUTE PROCEDURE set_expense_unit();
>
> Each time it runs, I get this error:
>
> ERROR: record t is unassigned yet
>
> Any ideas what this means?
Means the "SELECT INTO t" failed to find a matching row.
You'd better check that with an
if NOT FOUND then
RAISE ...
end if;
directly after the SELECT to get your own, more appropriate
error message.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #
From | Date | Subject | |
---|---|---|---|
Next Message | Jan Wieck | 2000-05-01 21:41:19 | Re: referencial integrity constraint bug in version 7.0 beta 55 |
Previous Message | Kevin Heflin | 2000-05-01 20:11:45 | multiple queries using PHP |