function - Dynamic Sql: Create array from records using array of column names -


i pulling of column_names (cname1) crosstab table made. there thousands of these column names combined them array. want use dynamic sql (or whatever works) use column_names make array based off of records of same crosstab table. keep getting error:

error: missing "loop" @ end of sql expression 

.

create or replace function mffcu.test_ty_hey()  returns setof record  language plpgsql $function$ declare        cname1 text;          begin   cname1 in select array_agg(column_name) useme from( select column_name::text information_schema.columns table_name = 'crosstab_183'  , ordinal_position != 1 ) fin join mffcu.crosstab_183 on fin.id = a.id;  loop   sql2 ='select distinct array['|| columnname ||'] mffcu.crosstab_183'; execute sql2; end loop; end; $function$ 

i cannot life of me figure out why i'm getting error.

 cname1 in select array_agg(column_name) useme from( select column_name::text information_schema.columns table_name = 'crosstab_183'  , ordinal_position != 1 ) fin join mffcu.crosstab_183 on fin.id = a.id; --here should not semicolon! loop 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -