Re: INSERTing rows from external file

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: INSERTing rows from external file
Дата
Msg-id 005a01cc5c5e$e8fa9800$baefc800$@yahoo.com
обсуждение исходный текст
Ответ на INSERTing rows from external file  (Rich Shepard <rshepard@appl-ecosys.com>)
Список pgsql-general
>> -----Original Message-----
>> From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Rich Shepard
>> Sent: Tuesday, August 16, 2011 5:34 PM
>> To: pgsql-general@postgresql.org
>> Subject: [GENERAL] INSERTing rows from external file
>>
>>    I have a file with 5500 rows formated as 'INSERT INTO <table>
>> (column_names) VALUES <values>;' that I thought I could read using psql
from the command line. However, the syntax, 'psql <database_name> <
filename.sql'
>>
>>
>> throws an error at the beginning of the first INSERT statement.

Prove It...

I do not use psql in this manner but what you are trying to do should work.
One thing that it may behoove you to do is clean up the file so that the

INSERT INTO table (columns) VALUES

Part only appears once.  Then, for each "VALUES (....);" line you should
replace the semi-colon with a comma (except the final one).

Thus:
INSERT INTO table (col) VALUES (1);
INSERT INTO table (col) VALUES (2);
INSERT INTO table (col) VALUES (3);

Becomes:
INSERT INTO table (col) VALUES (1),
(2),
(3);

This is considerably faster to execute.   5500 rows should be OK to do in a
single statement but anything beyond should probably result in a separate
INSERT being added (and maybe a COMMIT).

David J.




В списке pgsql-general по дате отправления:

Предыдущее
От: Greg Smith
Дата:
Сообщение: Re: INSERTing rows from external file
Следующее
От: Rich Shepard
Дата:
Сообщение: Re: INSERTing rows from external file