Re: BUG #2451: Short column names return no values within function

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Alex Weslowski <aweslowski(at)rpa(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2451: Short column names return no values within function
Date: 2006-05-23 15:51:18
Message-ID: 20060523155118.GA51120@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, May 23, 2006 at 03:27:01AM +0000, Alex Weslowski wrote:
> Below is code for duplicating this error. Fields "Peg" and "Rs03" and "Rs12"
> are absent from returned record (either Record or Cursor) even though the
> values in the table are not null.

The function declares variables with the same names as table columns;
that makes queries like "SELECT Symbol, RS03, RS12, Peg ..." ambiguous
because it's not clear whether those names refer to columns or to
variables.

> Problem might be related to type conversion (NULL converts to '' which has
> no meaning to INT or NUMERIC).
>
> Problem is fixed by renaming columns to "Peg_Ratio" and "RS03RS" and
> "RS12RS". So, there is something more going on here, related to length of
> column name.

Type conversion and label length aren't relevant -- the problem is
due to using the same label to refer to multiple things. Use different
names for the variables or qualify the column names in the query
("SELECT t.symbol, t.rs03, t.rs12, t.peg FROM testbug AS t ...").

--
Michael Fuhr

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Robert Treat 2006-05-24 13:34:52 BUG #2452: Error w/ pg_restore and blobs
Previous Message Tom Lane 2006-05-23 15:50:17 Re: BUG #2451: Short column names return no values within function