pipe text to copy statement stdin input

From: Scott Frankel <frankel(at)circlesfx(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: pipe text to copy statement stdin input
Date: 2011-06-21 19:43:11
Message-ID: 767ACBF2-CA22-49FD-B9B8-BD8CF0DE48AC@circlesfx.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hi all,

Is there a way to pipe text into a COPY statement's stdin input using
cmd-line psql?

I'm using the following syntax to enter large strings of text into a
table. The text itself has a json-like syntax that has the potential
for carrying numerous special characters.

COPY mytable(name, description, text) FROM stdin;
<the text>
\.

Problem is that my terminal's copy-paste buffer is much smaller than
the text I need to insert.

Note:
- I do not have superuser perms for the db, so passing a file instead
of stdin is not an option.

- Ditto for using \i to import a file.

- The db is password protected, so invoking `psql` as a non-
interactive command may not be possible. Right?

- If I'm wrong, anyone have example syntax of how to create a valid
COPY statement? I've found an interesting OSX cmd-line util that
copies/pastes between Terminal and the "pasteboard." Though I think
this just gets bitten by the file restriction anyway, eg:

% cat bigfile.txt > pbcopy
% psql DBNAME USERNAME (PASSWORD???) <<EOF
COPY mytable(name, description, text) FROM stdin;
pbpaste > stdin(???)
\.

pqsl 8.3
OSX 10.5.8
Terminal

Suggestions greatly appreciated!

Thanks
Scott

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vincent Veyron 2011-06-21 19:50:28 Re: Tuning for a tiny database
Previous Message Sylvain Rabot 2011-06-21 19:37:12 Re: Partitioning and constraint exclusion