I have created a request for my own use, that I use in 2 times :
Don't know if I can change it into a function, because in most of time I need to change a column type (for exemple, transforming the SCR or 'the_geom")
WITH param AS (
SELECT
'public' AS my_schema, -- enter the schema name
'my_table' AS my_table, -- enter the table name
ARRAY['the_geom'] AS excluded_fields -- enter the field(s) you want to exclude, separated with commas
)
SELECT format('SELECT %s FROM %I.%I;',
string_agg(quote_ident(column_name), ', '),
param.my_schema,
param.my_table)
FROM information_schema.columns, param
WHERE table_schema = param.my_schema
AND table_name = param.my_table
AND column_name <> ALL (param.excluded_fields )
GROUP BY param.my_schema, param.my_table;