pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Emi Lu <emilu@encs.concordia.ca>
To: pgsql-sql@postgresql.org
Subject: in PlPgSQL function, how to use variable in a "select ... into .. where " query
Date: Fri, 17 Mar 2006 12:52:53 -0500
Message-ID: <441AF775.7060006@encs.concordia.ca> (raw)

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







view thread (5+ messages)  latest in thread

Message-ID: <441AF775.7060006@encs.concordia.ca>
Permalink:  ../441AF775.7060006@encs.concordia.ca/
Also on:    postgresql.org/message-id/441AF775.7060006@encs.concordia.ca

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: emilu@encs.concordia.ca
  Subject: Re: in PlPgSQL function, how to use variable in a "select ... into .. where " query
  In-Reply-To: <441AF775.7060006@encs.concordia.ca>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox