psql in the command line
psql in the command line
От:
<Aniko.Badzong@swisscom.com>
Дата:
Hi
I need some help regarding psql syntax.
I would like to copy text files into the database from the command line in a script.
I have found already how can I do it as user postrgres:test:/opt/pgsql# echo "copy test from '/data/log/bla';" | psql logdb
COPYBut when I try to execute it as root user I get the following error:
[est/data/log] su - postgres -c "echo 'copy test from /data/log/bla;'| psql logdb"
ERROR: syntax error at or near "/" at character 16
LINE 1: copy test from /data/log/bla;
I have already tried with all kind of double and single quotes but it does not work.
Anybody has an idea how can I make it run?Thanks and regards
Aniko
Re: psql in the command line
От:
Alvaro Herrera <alvherre@alvh.no-ip.org>
Дата:
Aniko.Badzong@swisscom.com wrote: > test:/opt/pgsql# echo "copy test from '/data/log/bla';" | psql logdb > COPY > > But when I try to execute it as root user I get the following error: > > [est/data/log] su - postgres -c "echo 'copy test from /data/log/bla;'| > psql logdb" > ERROR: syntax error at or near "/" at character 16 > LINE 1: copy test from /data/log/bla; This is clearly not the same line. The quotes are not in the same position as in the line above. su - postgres -c "psql logdb -c 'copy test from \'data/log/bla\''" -- Alvaro Herrera http://www.advogato.org/person/alvherre "Es filósofo el que disfruta con los enigmas" (G. Coli)
Re: psql in the command line
От:
"Owen Jacobson" <ojacobson@osl.com>
Дата:
Alvaro Herrera wrote: > Aniko.Badzong@swisscom.com wrote: > > > test:/opt/pgsql# echo "copy test from '/data/log/bla';" | psql logdb > > COPY > > > > But when I try to execute it as root user I get the following error: > > > > [est/data/log] su - postgres -c "echo 'copy test from > /data/log/bla;'| > > psql logdb" > > ERROR: syntax error at or near "/" at character 16 > > LINE 1: copy test from /data/log/bla; > > This is clearly not the same line. The quotes are not in the same > position as in the line above. > > su - postgres -c "psql logdb -c 'copy test from \'data/log/bla\''" Or, preferably: $ echo "copy test from '/data/log/bla';" | sudo -u postgres psql logdb HTH, Owen