"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