Re: Need help to dynamically access to colomns in function!

From: Ivan Pavlov <ivan(dot)pavlov(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Need help to dynamically access to colomns in function!
Date: 2008-12-16 20:55:03
Message-ID: e7403312-468d-4acd-a235-8ac4787043fe@w39g2000prb.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

If you need them one by one why fetch them into tmprec? Take a look at
the docs for FETCH:
http://www.postgresql.org/docs/8.3/static/sql-fetch.html

especially the FETCH ABSOLUTE...

regards,
Ivan Pavlov

On Dec 16, 3:37 pm, aesthete2(dot)(dot)(dot)(at)gmail(dot)com ("Иван Марков") wrote:
> Hello. I have table classif with columns:
> ... , group1, group2, group3, ... , group48, ...
>
> In function i do query and want run on every row and dynamically operate on
> columns from group1 to group20. I do something like this:
>
> OPEN curs FOR select * from classif;
>  loop
>     fetch curs into tmprec;
>     exit when not found;
>
>     for I in 1..20 loop
>         ...
>     -- problem code is:
>         value := tmprec.group{I};
>     -- i cannot dynamically access to group1, group2, ... colomns according
> to "I" variable.
>     ...
>
>     end loop;
> end loop;
>
> I have to manually identify and handle each entry without a cycle do
> something like this:
> value := tmprec.group1;
> ...
> value := tmprec.group2;
> ...
> value := tmprec.group2;
> ...
> value := tmprec.group20;
>
> Please help me to do it dynamically with a loop, depending on the I?
> something like this in a loop:
> value := tmprec.group{I};
>
> Thanks.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Pavlov 2008-12-16 21:04:53 Re: Need help to dynamically access to colomns in function!
Previous Message Gauthier, Dave 2008-12-16 20:41:53 Re: Isolating a record column from a PL-Pgsql function call ?