I am quite new to the postgresql.
what is the best way to achieve this?
SELECT get_columns() FROM table_name;
get_columns(
In order to write a dynamic query you would have to do something like:
EXECUTE 'SELECT '|| get_columns()|| ' FROM table_name' INTO results
Please read the documentation: http://developer.postgresql.org/pgdocs/postgres/plpgsql-statements.html