I have a SQL function in PostgreSQL which returns the Column names of the table dynamically.following is the function that returns me the list of column names ( formatted ).
FUNCTION
CREATE OR REPLACE FUNCTION falc_app.get_quoted_column_names_for_a_table(sel_table_name text)
RETURNS TABLE(
script text
)
AS
$$
select array_to_string(
array(
select CAST ('|| quote_nullable(' || (column_name) ||') || ' as text) as script
FROM information_schema.COLUMNS
WHERE COLUMNS.table_schema = 'falc_app'
AND COLUMNS.TABLE_NAME = sel_table_name
ORDER BY COLUMNS.ordinal_position ), ''','' ')
$$
LANGUAGE sql;
OUTPUT
'col_username','col_password',......
PROBLEM
When I am trying to select on this function using the below code it works fine.
select falc_app.get_column_names_for_a_table(usertable);
but when I try to use this inside another function's code what happens is it doesn't get resolved to column names rather It gets resolved to below output, is there any way to get the same behavior like when selecting the function using a select statement
|| quote_nullable(col_username) || ',' || quote_nullable(col_password) ||......