Thread: Bug in plpgsql with execute ...

Bug in plpgsql with execute ...

From
Albert
Date:
Hi,

i think i found a bug in the pgsql interpreter. Platform is
Linux-2.4.0 on Intel, Postgres-Version is 7.1.1 .

The Problem:

I want to use a table name in a select statement within a function,
where the table name comes in as argument. It only works, if at all,
inside an execute statement. When redirecting the result into a
variable with INTO, the parser fails.

Example:

assume the following table:
CREATE TABLE bla (
  key  INT,
  value INT
);

fill it with some stuff:
INSERT INTO bla VALUES(3, 4);

Now the function:
CREATE FUNCTION itest(varchar(40), INT)
returns INT
AS 'DECLARE  res INT;

  BEGIN
    execute ''select INTO res value from '' || $1 || '' where key = '' || $2;
    RETURN res;
  END;'
LANGUAGE 'plpgsql';

Now calling
SELECT itest('bla', 3);
(what should work in my opinion) results in:
ERROR:  parser: parse error at or near "INTO"
DEBUG:  Last error occured while executing PL/pgSQL function itest
DEBUG:  line 4 at execute statement
ERROR:  parser: parse error at or near "INTO"

Removing the 'INTO res' makes things work.

Please check. It might be desirable to have the table name passed
as argument to a function for more reusable functions.

Regards and thanks, Postgres is Ultra-cool,

Albert Flügel

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 In a world without fences - who needs GATES ?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Albert Flügel                           -o
 Westermühlstraße 22                     /O\
 80469 München                            ^
 Tel: 089-2010895
 E-mail: af@muc.de
         a.fluegel@science-computing.de
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
finger af@muc.de for PGP public key
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~