Re: Piping CSV data to psql when executing COPY .. FROM STDIN - Mailing list pgsql-general

From Sam Mason
Subject Re: Piping CSV data to psql when executing COPY .. FROM STDIN
Date
Msg-id 20081028124015.GV2459@frubble.xen.chris-lamb.co.uk
Whole thread Raw
In response to Piping CSV data to psql when executing COPY .. FROM STDIN  (Allan Kamau <allank@sanbi.ac.za>)
Responses Re: Piping CSV data to psql when executing COPY .. FROM STDIN  (Allan Kamau <allank@sanbi.ac.za>)
List pgsql-general
On Tue, Oct 28, 2008 at 01:25:00PM +0200, Allan Kamau wrote:
> The alternative I am attempting is to use "COPY abc FROM STDIN WITH
> HEADER". I pipe the contents of the CSV file on my PC to the psql
> command (that connects to the remote PC) while issuing this copy command.
> This does seems not to work.

It does whenever I try it and if you've ever restored from a pg_dump
then you've used it as well!

> Is there a way around it.

When I've had a CSV file and needed to bung it into a database, I've
tended to end up with shell scripts like this before:

  ( echo 'COPY abc FROM STDIN WITH CSV HEADER;'
    cat "$1"
    echo '\.'
  ) | psql

an alternative is to use the "\copy" feature inside psql that does this
sort of thing internally.  One thing to be aware of is that it doesn't
expect a semicolon at the end of the line, but is otherwise the same as
the SQL COPY command.


  Sam

pgsql-general by date:

Previous
From: Sam Mason
Date:
Subject: Re: How to know the password for the user 'postgres'
Next
From: Thomas
Date:
Subject: Re: How to know the password for the user 'postgres'