Record Types Structure in PL/pgSQL

Started by Diego Sanchez R.almost 19 years ago4 messagesgeneral
Jump to latest
#1Diego Sanchez R.
dmsanchezr@gmail.com

Hi there.

Is there any way of determining the actual structure of a record variable?
E. g. I've written a small script to do some calculations over some fields
with a dinamically generated query. It looks like this:

create function foo(text) returns void as
$$
declare
a_record record;
my_query alias for $1;
begin
for a_record in execute my_query loop
-- Do some calculations
end loop;
return;
end;
$$
language plpgsql;

The question is: how could I possibly get the field names and other
information about the record a_record? I appreciate any suggestions or tips
about this.

Best regards.

--
Diego M. Sánchez

#2Bart Degryse
Bart.Degryse@indicator.be
In reply to: Diego Sanchez R. (#1)
Re: Record Types Structure in PL/pgSQL

Impossible in plpgsql. Use plperl instead.

"Diego Sanchez R." <dmsanchezr@gmail.com> 2007-06-08 14:14 >>>

Hi there.

Is there any way of determining the actual structure of a record
variable? E. g. I've written a small script to do some calculations
over some fields with a dinamically generated query. It looks like
this:

create function foo(text) returns void as
$$
declare
a_record record;
my_query alias for $1;
begin
for a_record in execute my_query loop
-- Do some calculations
end loop;
return;
end;
$$
language plpgsql;

The question is: how could I possibly get the field names and other
information about the record a_record? I appreciate any suggestions or
tips about this.

Best regards.

--
Diego M. S�nchez

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Diego Sanchez R. (#1)
Re: Record Types Structure in PL/pgSQL

"Diego Sanchez R." <dmsanchezr@gmail.com> writes:

Is there any way of determining the actual structure of a record variable?

Not in plpgsql; even if the info were exposed, you couldn't do anything
very useful because that language is strongly typed.

In some of the other PLs you could do it --- eg, in plperl the field
names are keys of a hash. Or as a last resort there's always C.

regards, tom lane

#4Merlin Moncure
mmoncure@gmail.com
In reply to: Tom Lane (#3)
Re: Record Types Structure in PL/pgSQL

On 6/8/07, Tom Lane <tgl@sss.pgh.pa.us> wrote:

"Diego Sanchez R." <dmsanchezr@gmail.com> writes:

Is there any way of determining the actual structure of a record variable?

Not in plpgsql; even if the info were exposed, you couldn't do anything
very useful because that language is strongly typed.

Well, you could do lots of useful things via dynamic sql...

merlin