postgresql - Retrieve dynamicaly the columns of a records -


my sql statement built dynamicaly. have like

strsql := 'select name, tel, adress, activity_id filtre_1, country_id filtre_2, ... ... ...'

i can have 1 n filter, , filter_1 can activity_id country_id, order in not important.

how can retrieve values of filter_1, filter_2 don't know how many request send back?

normaly retrieve values, :

for rowresult in execute strsql loop         name := rowresult.name         tel := rowresult.tel         adress := rowresult.adress         filtre_1 := rowresult.filtre_1         filtre_2 := rowresult.filtre_2 end loop; 

as cannot done, like

for rowresult in execute strsql loop         name := rowresult.name         tel := rowresult.tel         adress := rowresult.adress         filtre_1 := rowresult("filtre_1")         filtre_2 := rowresult("filtre_2") end loop; 

but rowresult(stringfield) not exist.

is have idea?

thanks

may there're more efficient ways, can access fields anonymous records converting array:

strsql := 'select name, activity_id, country_id test activity_id = 2 , country_id = 1'; rowresult in execute strsql loop     temp := string_to_array(trim(rowresult::text, '()'), ',');     activity_id := temp[2];     country_id := temp[3]; end loop; 

see sql fiddle demo

i think it's possible use hstore that, cannot test right now:

    temp := hstore(rowresult);     activity_id := temp -> 'f2'     country_id := temp -> 'f3' 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -