Re: Converting a proceedure from SOLID to Postgres

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Converting a proceedure from SOLID to Postgres
Дата
Msg-id 2682.989018426@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Converting a proceedure from SOLID to Postgres  ("Bob Whitehouse" <bwhitehouse@geeknest.com>)
Список pgsql-novice
"Bob Whitehouse" <bwhitehouse@geeknest.com> writes:
> When I run this I get this error message:

> SQL: select get_last_respondent(1290)
> [Fri May  4 16:30:40 2001] null: DBD::Pg::st execute failed: ERROR:
> unexpected SELECT query in exec_stmt_execsql()

plpgsql believes (for no good reason AFAICS) that a SELECT that doesn't
put its results someplace must be a mistake.  Therefore it wants you
to do SELECT INTO rather than plain SELECT.  If you're only doing the
SELECT so that you can check FOUND or ROW_COUNT, you still need to
select into a dummy variable.

As near as I can tell, the function you are trying to translate also
does a SELECT INTO and returns the result of that select (if
successful).  So in reality, your translation is wrong anyway.
I think you want something like

    declare
        person int4;
    begin

          SELECT h.who INTO person
          FROM   history h, issues iss
          WHERE  iss.id = int_issue_id_var
          AND    iss.id = h.issue
          AND    h.h_type = 3
          AND    h.who <> iss.submitter
          ORDER BY h.id DESC LIMIT 1;

          IF NOT FOUND THEN
                 person := 0;
          END IF;

          RETURN person;

but I'm just guessing...

            regards, tom lane

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

Предыдущее
От: "Bob Whitehouse"
Дата:
Сообщение: Converting a proceedure from SOLID to Postgres
Следующее
От: Tom Lane
Дата:
Сообщение: Re: unique (a,b)?