Re: PLPGSQL Fetching rows

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: PLPGSQL Fetching rows
Дата
Msg-id 1724.1053463466@sss.pgh.pa.us
обсуждение исходный текст
Ответ на PLPGSQL Fetching rows  (Mark Nelson <mn@tardis.cx>)
Список pgsql-general
Mark Nelson <mn@tardis.cx> writes:
> CREATE FUNCTION UpdateNextProjectCode() RETURNS OPAQUE AS '
>   DECLARE
>     project_code          INTEGER;
      ^^^^^^^^^^^^

>     OPEN used_project_codes FOR SELECT project_code FROM projects WHERE
                                         ^^^^^^^^^^^^
>        project_code > 0 ORDER BY project_code ASC;

It's a bad idea to use plpgsql variable names that match field or table
names that you are using in the same function.  plpgsql generally
assumes that you want the variable, not the field or table.  In this
case, what the SQL engine saw was effectively

    SELECT NULL FROM projects WHERE NULL > 0 ORDER BY NULL ASC;

since the variable project_code contains NULL at the time the OPEN
executes.

            regards, tom lane

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

Предыдущее
От: Network Administrator
Дата:
Сообщение: Fwd: Re: mod_perl + PostgreSQL implementation
Следующее
От: "Dmitri Bichko"
Дата:
Сообщение: Re: Subqueries and the optimizer