Re: create batch script to import into postgres tables

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: create batch script to import into postgres tables
Дата
Msg-id cd3af30c-41a2-4df1-d41e-6316b692227e@aklaver.com
обсуждение исходный текст
Ответ на Re: create batch script to import into postgres tables  (Pepe TD Vo <pepevo@yahoo.com>)
Ответы Re: create batch script to import into postgres tables  (Pepe TD Vo <pepevo@yahoo.com>)
Re: create batch script to import into postgres tables  (Pepe TD Vo <pepevo@yahoo.com>)
Список pgsql-admin
On 6/18/20 8:20 AM, Pepe TD Vo wrote:

Please don't top post. The preferred style on this list is inline or 
bottom posting(https://en.wikipedia.org/wiki/Posting_style).

> I have a Postgresql client installed and connected.  how can i create a 
> batch script running from the client window?

Create a file with commands in it like the example from Christopher 
Browne that was posted earlier:

"There is no single straightforward answer to that.


Supposing I want a batch to either all be processed, or to all not process,
then I might write a sql file like:


begin;
\copy table_1 (c1, c2, c3) from '/path/tabledata1.csv' csv header;
\copy table_2 (c1, c2, c3) from '/path/tabledata2.csv' csv header;
\copy table_3 (c1, c2, c3) from '/path/tabledata3.csv' csv header;
commit;


But you may be fine with having a separate SQL script for each table.


There will be conditions where one or the other is more appropriate, and
that will be based on the requirements of the process."

Then point psql at it:

psql -d some_db -h some_host -U some_user -f the_file

Be aware that \copy is all or nothing. If there is a single failure in 
the copying the whole copy will rollback. Given that the one file per 
table might be preferable.

> 
> **
> *Bach-Nga
> 



-- 
Adrian Klaver
adrian.klaver@aklaver.com



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

Предыдущее
От: Hotmail
Дата:
Сообщение: Any optimizations using oracle_fdw with oracle tables that haveclob columns?
Следующее
От: Pepe TD Vo
Дата:
Сообщение: Re: create batch script to import into postgres tables