If, on the wild chance you're an emacs user, if the section is in a
".sql" buffer Ctrl-C Ctrl-B will send the entire buffer. Not sure if
there's a practical limit on the number of line/statements, but I've
used this with a couple of "pages" worth of sql.
On 07/07/2016 11:48 AM, Dmitry Shalashov wrote:
Oh sweet! Thanks!
Dmitry Shalashov, surfingbird.ru <http://surfingbird.ru> & relap.io
<http://relap.io>
2016-07-07 20:39 GMT+03:00 Scott Mead <sco...@openscg.com
<mailto:sco...@openscg.com>>:
On Thu, Jul 7, 2016 at 1:30 PM, Dmitry Shalashov
<skau...@gmail.com <mailto:skau...@gmail.com>> wrote:
Hi Sameer,
I am trying to copy-paste (and execute) random snippets of SQL
to psql console.
There is another ways to do it, which do not involve
copy-paste, but I am wondering why is copy-paste won't work.
What exactly is happening there...
Dmitry Shalashov, surfingbird.ru <http://surfingbird.ru> &
relap.io <http://relap.io>
2016-07-07 20:26 GMT+03:00 Sameer Kumar
<sameer.ku...@ashnik.com <mailto:sameer.ku...@ashnik.com>>:
On Fri, 8 Jul 2016, 1:23 a.m. Dmitry Shalashov,
<skau...@gmail.com <mailto:skau...@gmail.com>> wrote:
Hi everyone.
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
<http://ati.su>',0,NULL,5);
INSERT INTO oko_topsites
VALUES('russian_federation'b2b=> INSERT INTO
oko_topsites VALUES('russian_federation','atn.ua
<http://atn.ua>',0,NULL,5);
b2b=> INSERT INTO oko_topsites
VALUES('russian_federation','audit-it.ru
<http://audit-it.ru>',0,NULL,5);
b2b=> INSERT INTO oko_topsites
VALUES('russian_federation','aup.ru
<http://aup.ru>',0,NULL,5);
'
b2b=> INSERT INTO oko_topsites
VALUES('russian_federation','autocentre.ua
<http://autocentre.ua>',0,NULL,5);
b2b=> INSERT INTO oko_topsites
VALUES('russian_federation','autodoc.ru
<http://autodoc.ru>',0,NULL,5);
b2b=> INSERT INTO oko_topsites
VALUES('russian_federation','calend.ru <http://calend.ru>'
b2b(> INSERT INTO oko_topsites
VALUES('russian_federation','calorizator.ru
<http://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). Paste
your data, then save-close the file. It will put you back into
psql and execute the command for you.
--Scott
What are you exactly aiming to do?
Have you tried -
psql < myfile
Dmitry Shalashov, surfingbird.ru
<http://surfingbird.ru> & relap.io <http://relap.io>
--
--
Best Regards
Sameer Kumar | DB Solution Architect
*ASHNIK PTE. LTD.*
101 Cecil Street, #11-11 Tong Eng Building, Singapore 069 533
T: +65 6438 3504 | M: +65 8110 0350 | www.ashnik.com
--
--
Scott Mead
Sr. Architect
/OpenSCG <http://openscg.com>/
http://openscg.com