79415240

Date: 2025-02-05 15:17:55
Score: 0.5
Natty:
Report link

I have created a request for my own use, that I use in 2 times :

  1. I use postgres to generate my request
  2. I copy the result of this request, change it if necessary

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;
Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Karl