I working in PostgreSQL past years, but i had no idea about array concept and how to handle array in PostgreSQL. i need a dynamic query for selecting columns in multiple table and the result will be in cursor, columns names should be dynamically will change.
for e.g (in a multiple table totally 30 columns is there If user need col1, col5,col6,col25), so select statement query will be dynamically will change like:
select col1, col5,col6,col25 from table ....
another user need col2,col5,col7,col29,col26, select statement will change dynamically as
select col2,col5,col7,col29,col26 from table .... and so on.
stored procedure passing parameters will be array
create or replace function func_my_method(check_in character varying, sel character varying[])...
this sel[] contains like
sel[0]:='col1_name'
sel[1]:='col5_name'
sel[2]:='col6_name'
sel[3]:='col25_name'
so first we have to split the array values in separate variable and these variable will be assumed in select statement will be
'select'||col1, col5,col6,col25||'from......'
Finally want to say briefly I need to pass an array in parameters and have to separate a array values and it will assign to separate variables. these variable will use to select a statement in dynamic manner
refcursor
? rextester.com/FMCUW60860 -- Although please don't forget to quote column names with eitherformat()
orquote_ident()
to minimize SQL injection possibility.