Skip site navigation (1) Skip section navigation (2)

Bug in plpgsql with execute ...

From: Albert <af(at)muc(dot)de>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Bug in plpgsql with execute ...
Date: 2001-05-10 15:06:30
Message-ID: 20010510170630.A1741@orion (view raw or flat)
Thread:
Lists: pgsql-bugs
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(at)muc(dot)de
         a(dot)fluegel(at)science-computing(dot)de
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
finger af(at)muc(dot)de for PGP public key
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pgsql-bugs by date

Next:From: Peter EisentrautDate: 2001-05-10 18:32:54
Subject: Re: Paths for C functions (was Re: Re: backend dies on 7.1.1 loading large datamodel.)
Previous:From: Tom LaneDate: 2001-05-10 13:55:50
Subject: Re: [HACKERS] Re: date conversion (was Re: Re: v7.1.1 branched and released on Tuesday ...)

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group