Re: pasting a lot of commands to psql

From: Sameer Kumar <sameer(dot)kumar(at)ashnik(dot)com>
To: Dmitry Shalashov <skaurus(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: pasting a lot of commands to psql
Date: 2016-07-07 17:37:40
Message-ID: CADp-Sm6P2JizO-HbbKJbL9fXuE9gBSE6xmNtp5nDuAtbf92=Bg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jul 8, 2016 at 1:31 AM Dmitry Shalashov <skaurus(at)gmail(dot)com> wrote:

> Hi Sameer,
>
> I am trying to copy-paste (and execute) random snippets of SQL to psql
> console.
>

Why? Is it some migration of data? You are better off exporting the data to
csv and use COPY command.

>
> 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...
>

Have you looked at this line in the file-
INSERT INTO oko_topsites VALUES('russian_federation','calend.ru'

Either the line in file lacks a closing parenthesis or may be your terminal
is not able to process so many characters so fast and hence it is
missing/skipping on some characters. I have experiences this behavior, not
just with psql but with usual shell when I use utterly slow VPN or when I
use screen share tools like TeamViewer or WebEx etc over slow network

> Dmitry Shalashov, surfingbird.ru & relap.io
>
> 2016-07-07 20:26 GMT+03:00 Sameer Kumar <sameer(dot)kumar(at)ashnik(dot)com>:
>
>>
>>
>> On Fri, 8 Jul 2016, 1:23 a.m. Dmitry Shalashov, <skaurus(at)gmail(dot)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
>>> ',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);
>>>
>>>
The below is broken...

> 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 :-)
>>>
>>
>> What are you exactly aiming to do?
>>
>> Have you tried -
>> psql < myfile
>>
>>
>>
>>> Dmitry Shalashov, surfingbird.ru & 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
>>
>
> --
--
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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Scott Mead 2016-07-07 17:39:44 Re: pasting a lot of commands to psql
Previous Message Tom Lane 2016-07-07 17:37:13 Re: pasting a lot of commands to psql