Re: in PlPgSQL function, how to use variable in a "select ...

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: in PlPgSQL function, how to use variable in a "select ...
Date: 2006-03-17 19:50:32
Message-ID: 20060317195031.GA8508@webserv.wug-glas.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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-DYN

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 ===

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Emi Lu 2006-03-17 20:33:18 Re: in PlPgSQL function, how to use variable in a "select ...
Previous Message Emi Lu 2006-03-17 19:23:57 Re: in PlPgSQL function, how to use variable in a "select ...