Re: dynamic plpgsql command on a record type - Mailing list pgsql-general

From Richard Huxton
Subject Re: dynamic plpgsql command on a record type
Date
Msg-id 4B71491F.9020601@archonet.com
Whole thread Raw
In response to dynamic plpgsql command on a record type  (Willy-Bas Loos <willybas@gmail.com>)
List 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

pgsql-general by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: Order by and strings
Next
From: Shoaib Mir
Date:
Subject: Re: string reverse fucntion?