Re: The tuple structure of a not-yet-assigned record is indeterminate.

From: M L <novemberox(at)gmail(dot)com>
To: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: The tuple structure of a not-yet-assigned record is indeterminate.
Date: 2009-03-23 02:03:44
Message-ID: c11212cc0903221903v2bd35d30s3f7e417ac09fa496@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2009/3/23 Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>

> M L wrote:
>
> > CREATE TRIGGER league AFTER insert ON t_leagues FOR STATEMENT EXECUTE
> > PROCEDURE add_view();
> >
> > Then in psql I made an query and got error:
> >
> > league=# INSERT INTO t_leagues (name) VALUES('3liga');
> > ERROR: record "new" is not assigned yet
> > DETAIL: The tuple structure of a not-yet-assigned record is
> indeterminate.
> > CONTEXT: PL/pgSQL function "add_view" line 4 at RAISE
>

> `NEW' and `OLD' refer to the tuple operated on by this call of the
> trigger. They're not valid for FOR EACH STATEMENT triggers, since the
> statement might've added/modified/deleted zero or more than one tuple.
>
> If you want to see the values of the tuples modified, use a FOR EACH ROW
> trigger.
>
I was trying varius trigers when I use:
league=# CREATE OR REPLACE FUNCTION add_view() RETURNS trigger AS $$
DECLARE
someint integer;
BEGIN
RAISE NOTICE 'dodajesz nowa lige %', NEW.id;
someint := NEW.id;
RAISE NOTICE 'dodajesz nowa lige %', someint;
CREATE VIEW tabelka AS SELECT someint FROM t_matches;
RETURN NULL;
END;
$$ language plpgsql;

CREATE TRIGGER league AFTER insert ON t_leagues FOR EACH ROW EXECUTE
PROCEDURE add_view();

I've got:
league=# INSERT INTO t_leagues (name) VALUES('3liga');
NOTICE: dodajesz nowa lige 31
NOTICE: dodajesz nowa lige 31
ERROR: there is no parameter $1
CONTEXT: SQL statement "CREATE VIEW tabelka AS SELECT $1 FROM t_matches"
PL/pgSQL function "add_view" line 7 at SQL statement

Any ideas?

>
> > Whats wrong, I supposed that id is not reserverd at the moment
>
> That's not the case. Your trigger is being called *AFTER* the row is
> inserted, so the ID must've been assigned. In any case, default
> expressions (including those used to assign values from sequences) are
> actually evaluated even before the BEFORE triggers are invoked.
>

That was my first thought, that it should be already assigned.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greenhorn 2009-03-23 04:03:15 bash & postgres
Previous Message Craig Ringer 2009-03-23 01:11:18 Re: The tuple structure of a not-yet-assigned record is indeterminate.