From: | Jerry Sievers <gsievers19(at)comcast(dot)net> |
---|---|
To: | Kirk Wythers <kwythers(at)umn(dot)edu> |
Cc: | "pgsql-general\(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: psql copy from through bash |
Date: | 2013-01-11 20:19:41 |
Message-ID: | 87bocv1nhe.fsf@comcast.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Kirk Wythers <kwythers(at)umn(dot)edu> writes:
> 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
Well, I don't know what else could be wrong but suggest you get rid of
the backslash as in \copy and just say COPY which is the SQL command.
\copy is a psql macro and I'm not sure it's appropriate here.
And you win the "useless use of cat award" here too.
psql ... <infile
Of course one good reason for preferring cat is that you'll never
type > by mistake instead of < and clobber your data. Er, some shells
have a no-clobber option though.
HTH
> 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
>
--
Jerry Sievers
Postgres DBA/Development Consulting
e: postgres(dot)consulting(at)comcast(dot)net
p: 312.241.7800
From | Date | Subject | |
---|---|---|---|
Next Message | Sahagian, David | 2013-01-11 21:04:38 | changes "during checkpointing" |
Previous Message | Pavel Stehule | 2013-01-11 18:40:59 | Re: psql copy from through bash |