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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #2451: Short column names return no values within function
Дата
Msg-id 14843.1148399417@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #2451: Short column names return no values within function  ("Alex Weslowski" <aweslowski@rpa.com>)
Список pgsql-bugs
"Alex Weslowski" <aweslowski@rpa.com> writes:
> DECLARE
>     peg VARCHAR(5) := '';
>     rs03 VARCHAR(3) := '';
>     rs12 VARCHAR(3) := '';
>     rec RECORD;
> BEGIN
>     FOR rec IN SELECT Symbol, RS03, RS12, Peg
>     FROM TestBug WHERE Date=d
>     ORDER BY RS12 DESC LOOP

The problem is that you've got local variables shadowing the field names
you want to use.  What the SQL engine sees from that is

    SELECT Symbol, $1, $2, $3
    FROM TestBug WHERE Date=$4
    ORDER BY $5 DESC

and it just assigns random ?columnN? names to the record columns (which
are going to have useless empty-string values anyway).

Use different local variable names, or qualify the field references in
the SELECT, eg TestBug.RS03.

            regards, tom lane

В списке pgsql-bugs по дате отправления:

Предыдущее
От: "qinyan"
Дата:
Сообщение: missing or erroneous pg_hba.conf file
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: BUG #2451: Short column names return no values within function