X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C9956D8D9D for ; Tue, 13 Sep 2005 15:06:12 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 29775-08 for ; Tue, 13 Sep 2005 18:06:09 +0000 (GMT) Received: from fmed.uba.ar (mail.fmed.uba.ar [157.92.152.1]) by svr1.postgresql.org (Postfix) with ESMTP id 93782D8D7F for ; Tue, 13 Sep 2005 15:06:07 -0300 (ADT) Received: from webmail.fmed.uba.ar (localhost [127.0.0.1]) by fmed.uba.ar (Postfix) with SMTP id 2947A30180; Tue, 13 Sep 2005 15:09:42 -0300 (ART) Received: from 157.92.152.53 (proxying for unknown) (SquirrelMail authenticated user gherzig) by webmail.fmed.uba.ar with HTTP; Tue, 13 Sep 2005 15:09:42 -0300 (ART) Message-ID: <39044.157.92.152.53.1126634982.squirrel@webmail.fmed.uba.ar> In-Reply-To: <20050912230323.GA63469@winnie.fuhr.org> References: <56093.157.92.152.53.1126538482.squirrel@webmail.fmed.uba.ar> <20050912230323.GA63469@winnie.fuhr.org> Date: Tue, 13 Sep 2005 15:09:42 -0300 (ART) Subject: Re: refer a column as a varible name? From: gherzig@fmed.uba.ar To: "Michael Fuhr" Cc: gherzig@fmed.uba.ar, pgsql-sql@postgresql.org User-Agent: SquirrelMail/1.4.2 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Priority: 3 Importance: Normal X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.178 required=5 tests=[NO_REAL_NAME=0.178] X-Spam-Level: X-Archive-Number: 200509/146 X-Sequence-Number: 22693 Im using pg 8.0. I personally dont have problem in using pl/perl, but none of my companions is a perl programmer, so i guess the IF..THEN seems to be an easy (altough not preferable) solution. Thank you very much Michael. Gerardo > On Mon, Sep 12, 2005 at 12:21:22PM -0300, gherzig@fmed.uba.ar wrote: >> suppose the >> >> type mycolumn as (field1, varchar, field2 varchar) >> and >> >> field_name = ''field1'' >> >> and returnValue declared as mycolumn >> ... >> can i say returnValue.$field_name = ''ok''? > > To achieve this in PL/pgSQL you'll need to use a conditional statement > (IF field_name = 'field1' THEN ...). I'm not sure if a solution > involving EXECUTE is possible; if so then it's probably non-obvious. > > What version of PostgreSQL are you using, and do you have a requirement > to use PL/pgSQL? In 8.0 PL/Perl can return composite types and such > an assignment would be trivial: > > CREATE TYPE mycolumn AS (field1 varchar, field2 varchar); > > CREATE FUNCTION foo(varchar) RETURNS mycolumn AS $$ > my $field_name = $_[0]; > my $returnValue = {$field_name => "ok"}; > return $returnValue; > $$ LANGUAGE plperl IMMUTABLE STRICT; > > SELECT * FROM foo('field1'); > field1 | field2 > --------+-------- > ok | > (1 row) > > SELECT * FROM foo('field2'); > field1 | field2 > --------+-------- > | ok > (1 row) > > -- > Michael Fuhr > > ---------------------------(end of broadcast)--------------------------- > TIP 1: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly > > -- Gerardo Herzig Direccion General de Organizacion y Sistemas Facultad de Medicina U.B.A.