Let say that I have some sql file with like hundred of simple statements in it. I `cat` it, copy it to buffer, go to my beloved psql and insert it there.
But somewhere after first few lines it screws over:
b2b=> BEGIN;
b2b=> INSERT INTO oko_topsites VALUES('russian_federation','ati.su',0,NULL,5);
INSERT INTO oko_topsites VALUES('russian_federation'b2b=> INSERT INTO oko_topsites VALUES('russian_federation','atn.ua',0,NULL,5);
b2b=> INSERT INTO oko_topsites VALUES('russian_federation','audit-it.ru',0,NULL,5);
b2b=> INSERT INTO oko_topsites VALUES('russian_federation','aup.ru',0,NULL,5);
'
b2b=> INSERT INTO oko_topsites VALUES('russian_federation','autocentre.ua',0,NULL,5);
b2b=> INSERT INTO oko_topsites VALUES('russian_federation','autodoc.ru',0,NULL,5);
b2b=> INSERT INTO oko_topsites VALUES('russian_federation','calend.ru'
b2b(> INSERT INTO oko_topsites VALUES('russian_federation','calorizator.ru',0,NULL,5)
Unclosed quotes, unclosed parenthesis - anyway it wont work.
How to safely insert big number of statements to psql at once?
I am aware about "execute this file" \i option of psql, that is not the answer I am looking for, thanks :-)
My personal favorite for this exact thing is to use '\e'
When you are in psql, if you \e (on *nix) it will open a temp file in whatever your $EDITOR variable is set ( I use vim).
on windows, it actually pops up notepad.exe. Save and close, same behavior.
--Scott
Paste your data, then save-close the file. It will put you back into psql and execute the command for you.