From: Michael Fuhr <mike@fuhr.org>
To: gherzig@fmed.uba.ar
Cc: pgsql-sql@postgresql.org
Subject: Re: refer a column as a varible name?
Date: Mon, 12 Sep 2005 17:03:23 -0600
Message-ID: <20050912230323.GA63469@winnie.fuhr.org> (raw)
In-Reply-To: <56093.157.92.152.53.1126538482.squirrel@webmail.fmed.uba.ar>
References: <56093.157.92.152.53.1126538482.squirrel@webmail.fmed.uba.ar>
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
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: mike@fuhr.org, gherzig@fmed.uba.ar
Subject: Re: refer a column as a varible name?
In-Reply-To: <20050912230323.GA63469@winnie.fuhr.org>
* 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