Re: [HACKERS] plpgsql strangeness with select into <variable>

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Reinoud van Leeuwen <reinoud(at)xs4all(dot)nl>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: [HACKERS] plpgsql strangeness with select into <variable>
Date: 2003-07-18 16:19:16
Message-ID: 20030718091807.T95696-100000@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

On Fri, 18 Jul 2003, Josh Berkus wrote:

> > I'm debugging a trigger in plpgsql and for some reason or the "select
> > into <var>" does not seem to work. Here is an unaltered snippet of my
> > trigger code:
> >
> > raise notice ''this id : %'',NEW.id;
> >
> > select into i_hierarchy_id
> > hierarchy_id
> > from link_def LD,
> > link L,
> > object_link OL
> > where OL.id = NEW.id
> > and L.id = OL.link_id
> > and LD.id = L.link_def_id;
> >
> > raise notice ''i_hierarchy_id: %'',i_hierarchy_id;
> >
> >
> > in the log this results in:
> >
> > NOTICE: this id : 5265
> > NOTICE: i_hierarchy_id: <NULL>
> >
> > but when I perform the query on the command line I do get a result:
> >
> > select hierarchy_id
> > from link_def LD,
> > link L,
> > object_link OL
> > where OL.id = 5264
> > and L.id = OL.link_id
> > and LD.id = L.link_def_id;
> >
> > hierarchy_id
> > --------------
> > 1
> > (1 row)
> >
> > i_hierarchy_id is declared as integer and is not used before this code nor
> > as a column name anywhere.
> >
> > Does anyone have a clue what is going wrong? I use Postgresql 7.3.3 on
> > FreeBSD 4.5.
>
> Without seeing your full trigger code, I can't tell for sure. However, I
> would guess that your "SELECT INTO" statement is querying data that has not
> yet been created; it's an FK record waiting on a deferred trigger, or you're
> using a BEFORE trigger and querying the record which has not yet been
> committed.

Or perhaps you have a variable named hierarchy_id in the function which is
getting used rather than the column of the table in question. Seeing the
entire function might help.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2003-07-18 16:48:36 Another TODO for PL/pgSQL -- Dynamic colums
Previous Message Josh Berkus 2003-07-18 16:14:43 Re: [HACKERS] plpgsql strangeness with select into <variable>

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2003-07-18 16:38:25 Re: (trigger function) -> ERROR: NEW used in non-rule query
Previous Message Josh Berkus 2003-07-18 16:14:43 Re: [HACKERS] plpgsql strangeness with select into <variable>