Re: psql -f COPY from STDIN

Поиск
Список
Период
Сортировка
От Tarlika Elisabeth Schmitz
Тема Re: psql -f COPY from STDIN
Дата
Msg-id 20101113150402.67e3ddfe@dick.coachhouse
обсуждение исходный текст
Ответ на Re: psql -f COPY from STDIN  (Tarlika Elisabeth Schmitz <postgresql2@numerixtechnology.de>)
Список pgsql-sql
On Sat, 13 Nov 2010 12:01:35 +0000
Tarlika Elisabeth Schmitz <postgresql2@numerixtechnology.de> wrote:

>I'd like the store the COPY command in a separate file without
>specifying an input file name. I want to feed it the data from the
>shell script that calls psql


"STDIN: All rows are read from the same source that issued the command"
- As I understand now, this applies to both COPY and \COPY. In other
words the input file must contain command and data.


I have found a few solutions to achieve my objective:

1) using COPY FROM STDIN
cat event.csv | psql -c "$(cat event.sql)"

2) using COPY FROM STDIN
psql -f  <(cat event.sql event.csv)

3) using \COPY FROM PSTDIN
cat event.csv | psql -f event.sql

4) using \COPY FROM STDIN
psql -f  <(cat event.sql event.csv <(echo "\."))


What I don't like about \COPY is that it has to be on one line. Indeed
it can't be split over multiple lines, Tom, not with backslash either.

\COPY FROM STDIN requires the data to be terminated with "\." whereas
COPY is happy with EOF.

I'll go for 2) because it allows me to format the COPY command over
multiple lines.

-- 

Best Regards,
Tarlika Elisabeth Schmitz


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: psql -f COPY from STDIN
Следующее
От: berelith
Дата:
Сообщение: Need help with plpgsql function.