Re: dynamic plpgsql command on a record type

From: Richard Huxton <dev(at)archonet(dot)com>
To: Willy-Bas Loos <willybas(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: dynamic plpgsql command on a record type
Date: 2010-02-09 11:38:07
Message-ID: 4B71491F.9020601@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 09/02/10 11:07, Willy-Bas Loos wrote:
> Hi,
>
> in my plpgsql function I'm looping through tables and their fields and i
> want to return their field names and the corresponding values.
> It all works fine, except i can't retrieve the values, which is really a
> bummer.
> I tried a couple of things (in vain), of which this seemed the most
> promising:
...
> t_rec_out.field_value := t_record.t_fields[t_i]; --<==== happens here
...
> And then i get the error:
> ERROR: record "t_record" has no field "t_fields"
>
> Any tips there?

This isn't going to be practical in plpgsql. You can just about do it if
you want to build a "SELECT" statement and cast everything to text. Not
worth the trouble though. The problem is that plpgsql is very static in
its typing and just doesn't have the flexibility for this sort of task.

Use pltcl or plperl or plpython or one of the other more dynamic
languages. It's straightforward then.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Shoaib Mir 2010-02-09 11:41:32 Re: string reverse fucntion?
Previous Message Magnus Hagander 2010-02-09 11:37:08 Re: Order by and strings