pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: A. Kretschmer <andreas.kretschmer@schollglas.com>
To: pgsql-sql@postgresql.org
Subject: Re: in PlPgSQL function, how to use variable in a "select ...
Date: Fri, 17 Mar 2006 20:50:32 +0100
Message-ID: <20060317195031.GA8508@webserv.wug-glas.de> (raw)
In-Reply-To: <441B0CCD.9020704@encs.concordia.ca>
References: <441AF775.7060006@encs.concordia.ca>
	<684362e10603170956j20174d07q@mail.gmail.com>
	<441B0CCD.9020704@encs.concordia.ca>

am  17.03.2006, um 14:23:57 -0500 mailte Emi Lu folgendes:
> Does not work either, the whole function is:
> 
> create table t1(col1 varchar(3), col2 varchar(100));
> insert into t1 values('001', 'Result 1');
> insert into t1 values('002', 'Result 2');
> insert into t1 values('003', 'Result 3');
> 
> CREATE OR REPLACE FUNCTION test(VARCHAR) RETURNS VARCHAR AS $$
> DECLARE
>    col1_value                ALIAS FOR $1;                            
> cm_tableName           st1_legend.code_map_tablename%TYPE;   
> lengendTableName    VARCHAR := 't1';
>    query_value                VARCHAR ;
> BEGIN
> 
>    SELECT INTO cm_tableName col2 FROM lengendTableName WHERE col1 = 
> col1_value ;

This can't work, read the docu:
http://www.postgresql.org/docs/8.1/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-...

You should build a string with your SQL and EXECUTE this string.


HTH, Andreas
-- 
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47215,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
 ===    Schollglas Unternehmensgruppe    === 



view thread (5+ messages)  latest in thread

Message-ID: <20060317195031.GA8508@webserv.wug-glas.de>
Permalink:  ../20060317195031.GA8508@webserv.wug-glas.de/
Also on:    postgresql.org/message-id/20060317195031.GA8508@webserv.wug-glas.de

 · 

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: andreas.kretschmer@schollglas.com
  Subject: Re: in PlPgSQL function, how to use variable in a "select ...
  In-Reply-To: <20060317195031.GA8508@webserv.wug-glas.de>

* 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