in PlPgSQL function, how to use variable in a "select ... into .. where " query

From: Emi Lu <emilu(at)encs(dot)concordia(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: in PlPgSQL function, how to use variable in a "select ... into .. where " query
Date: 2006-03-17 17:52:53
Message-ID: 441AF775.7060006@encs.concordia.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello,

In pl/pgsql (postgresql 8.01), how to use variables in select .. into ..
command

CREATE OR REPLACE FUNCTION test(VARCHAR) RETURNS VARCHAR AS $$
DECLARE
var1 ALIAS FOR $1;
cm_tableName tableA.col1%TYPE;
T1 VARCHAR := 'sourceTable';
query_value VARCHAR ;
BEGIN

SELECT col2 INTO cm_tableName FROM T1 WHERE col1 = var1 ;
EXECUTE query_value;


RETURN cm_tableName;
END;
$$ language 'plpgsql' IMMUTABLE STRICT;

select test('abc');

Failed.

Also, tried "SELECT col2 INTO cm_tableName FROM || T1 WHERE col1 = ||
var1 " and
"SELECT col2 INTO cm_tableName FROM || T1 || WHERE col1 = || var1"

Failed as well.

T1 and var1 both are variables, may I how to use variables in a "select
... into " query please?

Thanks a lot,
Ying

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Emi Lu 2006-03-17 19:23:57 Re: in PlPgSQL function, how to use variable in a "select ...
Previous Message Markus Schaber 2006-03-17 15:50:09 Re: dump with lo