Thread: psql in the command line
<p><font face="Arial" size="2">Hi</font><p><font face="Arial" size="2">I need some help regarding psql syntax.</font><br/><font face="Arial" size="2">I would like to copy text files into the database from the command line ina script.</font><br /><font face="Arial" size="2">I have found already how can I do it as user postrgres:</font><p><spanlang="en-gb"><font face="Arial" size="2">test:/opt/pgsql# echo "copy test from '/data/log/bla';"| psql logdb</font></span><br /><span lang="en-gb"><font face="Arial" size="2">COPY</font></span><p><spanlang="de-ch"><font face="Arial" size="2">But when I try to execute it as root user I getthe following error:</font></span><p><span lang="de-ch"><font face="Arial" size="2">[est/data/log] su - postgres -c "echo'copy test from /data/log/bla;'| psql logdb"</font></span><br /><span lang="de-ch"><font face="Arial" size="2">ERROR: syntax error at or near "/" at character 16</font></span><br /><span lang="de-ch"><font face="Arial" size="2">LINE1: copy test from /data/log/bla;</font></span><br /><span lang="de-ch"><font face="Arial" size="2"> </font></span><br/><span lang="de-ch"><font face="Arial" size="2">I have already tried with all kind of double and singlequotes but it does not work.</font></span><br /><span lang="de-ch"><font face="Arial" size="2">Anybody has an ideahow can I make it run?</font></span><p><span lang="de-ch"><font face="Arial" size="2">Thanks and regards</font></span><br/><span lang="de-ch"><font face="Arial" size="2">Aniko</font></span>
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)
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