I am trying to get maintenance query from windows command line psql with COPY statement.(Windows 2012). The query produces maintenance query as output file. After that I wish to import maintenance query (reindex.sql) and execute with a scheduler. But I couldn't find it out why I couldnt execute script. There should be a comma trick which I couldn't solve.
psql -U postgres -c "COPY( SELECT 'REINDEX TABLE "' || schemaname || '"."' || relname || '";'FROM pg_stat_all_tables ORDER BY n_dead_tup DESC)TO 'E:\scripts\maintenance\reindex.sql';"