X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6FA419DC842 for ; Fri, 17 Mar 2006 15:50:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83227-02 for ; Fri, 17 Mar 2006 15:50:37 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.187]) by postgresql.org (Postfix) with ESMTP id DF7169DCC26 for ; Fri, 17 Mar 2006 15:50:34 -0400 (AST) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu9) with ESMTP (Nemesis), id 0ML2xA-1FKKy03jzy-0003LH; Fri, 17 Mar 2006 20:50:33 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1FKKy0-0002EI-00 for pgsql-sql@postgresql.org; Fri, 17 Mar 2006 20:50:32 +0100 Date: Fri, 17 Mar 2006 20:50:32 +0100 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: in PlPgSQL function, how to use variable in a "select ... Message-ID: <20060317195031.GA8508@webserv.wug-glas.de> Mail-Followup-To: "A. Kretschmer" , pgsql-sql@postgresql.org References: <441AF775.7060006@encs.concordia.ca> <684362e10603170956j20174d07q@mail.gmail.com> <441B0CCD.9020704@encs.concordia.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <441B0CCD.9020704@encs.concordia.ca> X-DEST: 208 X-MSMail-Priority: High X-Message-Flag: Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect. (Linus Torvalds) X-OS: Linux - weil ich es mir Wert bin! X-Info: registrierter Linux-User 97922 http://counter.li.org User-Agent: mutt-ng 1.5.9i (Linux) X-Provags-ID: kundenserver.de abuse@kundenserver.de login:51ea9561fc3f6d9539a2acd743e4748c X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.183 required=5 tests=[AWL=-0.211, MISSING_MIMEOLE=1.394] X-Spam-Score: 1.183 X-Spam-Level: * X-Archive-Number: 200603/253 X-Sequence-Number: 24599 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 ===