Warning
Work in progress, currently it can read from stdin and files, also it can save the output to a file BUT, I have not tested it on larger sql files, so there might be performance issues Will work on them
Single to multi line SQL
Goal of this project is to turn this
INSERT INTO films (code, title, did, date_prod, kind) VALUES ('B6717', 'Tampopo', 110, '1985-02-10', 'Comedy');
INSERT INTO films (code, title, did, date_prod, kind) VALUES ('HG120', 'The Dinner Game', 140, DEFAULT, 'Comedy');To this
INSERT INTO films (code, title, did, date_prod, kind) VALUES ('B6717', 'Tampopo', 110, '1985-02-10', 'Comedy'),
('HG120', 'The Dinner Game', 140, DEFAULT, 'Comedy');Examples from this stack overflow question
./s2m "SELECT * from here; insert into mail(id) values (1);insert into mail(id) values (2);"Or
./s2m "SELECT * from mail; \
INSERT into mail(id) values (1); \
INSERT into mail(id) values (2)"Tool supports reading files and printing output to standard out.
Use it like this:
./s2m -f export.sqlTo save the output to file, pass -o command line flag with the name of the file.
./s2m -f export.sql -o output.sqlAlso works with standard in
./s2m -o output.sql "SELECT * from mail; \
INSERT into mail(id) values (1); \
INSERT into mail(id) values (2)"Actually no, if you use Intellij/DataGrip or any other Jetbrains IDE, the IDE can do that for you.
If you are using pg_dump to generate an sql dump, and want to speed up the queries by turning them into multi line inserts, then just define rows per insert flag --rows-per-insert=100 <- insert number that works for your use case.
Read more here https://www.postgresql.org/docs/current/app-pgdump.html