Re: psql copy from through bash

From: Szymon Guz <mabewlun(at)gmail(dot)com>
To: Kirk Wythers <wythe001(at)umn(dot)edu>
Cc: Kirk Wythers <kwythers(at)umn(dot)edu>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: psql copy from through bash
Date: 2013-01-11 18:36:03
Message-ID: CAFjNrYvqiYSKMJK8z41F3MF02kR=qqwsDa7SpeV6Bw+h1rhxkg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 11 January 2013 19:32, Kirk Wythers <wythe001(at)umn(dot)edu> wrote:

>
> On Jan 11, 2013, at 12:18 PM, Szymon Guz <mabewlun(at)gmail(dot)com> wrote:
>
>
>
>
> On 11 January 2013 19:13, Kirk Wythers <kwythers(at)umn(dot)edu> wrote:
>
>> Can anyone see what I'm misisng? I am trying to run a psql "copy from"
>> command through a bash script to load a buch of cdv files into the same
>> table. I'm getting an error about the file "infile" not existing?
>>
>> #!/bin/sh
>>
>> for infile in /path_to_files/*.csv
>> do
>> cat infile | psql dbname -c "\copy table_name FROM stdin with
>> delimiter as ',' NULL AS 'NA' CSV HEADER"
>> done
>>
>>
>> Thanks in advance
>>
>> --
>> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-general
>>
>
>
> Hi Kirk,
> maybe try this:
>
> cat $infile |
>
>
>
> Oh my goodness! Thanks you.
>
> Once more quickie. It seems that I am going to be asked for my password
> every time psql loops through the copy statement.
>
> What is considered best practices to handle authentication? I am
> connecting locally, as myself as the user and I'm being asked for my user
> password. I added the -w (no-password) to the psql statement, but now
> assume I need to add a .pgpass file or something.
>
> Suggestions?
>
>
Add the password to ~/.pgpass
http://www.postgresql.org/docs/9.1/static/libpq-pgpass.html

Szymon

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2013-01-11 18:40:59 Re: psql copy from through bash
Previous Message Kirk Wythers 2013-01-11 18:32:58 Re: psql copy from through bash