Re: Dynamically access to field on a RECORD variable

From: Ricardo Vaz Mannrich <rvm_l1(at)silcom(dot)com(dot)br>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Dynamically access to field on a RECORD variable
Date: 2005-05-03 16:59:51
Message-ID: 1115139591.22502.20.camel@curitiba.silcom
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If it's not possible, can I create a function that gets a RECORD and a
tablename and returns the correct value. For example:

CREATE FUNCTION my_value(TEXT, RECORD) RETURNS TEXT AS '
DECLARE
table_name ALIAS FOR $1
rec ALIAS FOR $2
BEGIN
IF (table_name = 'my_table1') THEN
RETURN rec.my1_field;
ELSIF (table_name = 'my_table2') THEN
RETURN rec.my2.field;
...
END;
' LANGUAGE plpgsql;

Em Ter, 2005-05-03 às 11:52, Tom Lane escreveu:
> Ricardo Vaz Mannrich <rvm_l1(at)silcom(dot)com(dot)br> writes:
> > Is it possible?
>
> Not in plpgsql. I believe you could do it in any of the other PLs though.
>
> regards, tom lane
--
Ricardo Vaz Mannrich <rvm_l1(at)silcom(dot)com(dot)br>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2005-05-03 17:04:16 Re: postgresql 8 abort with signal 10
Previous Message Rich Shepard 2005-05-03 16:58:24 Adding Records With SERIAL Primary Key