[SQL] psql in the command line

2006-01-25 Thread Aniko.Badzong
Title: psql in the command line






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

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;

  

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





[SQL] FW: sql copy does not work

2006-03-02 Thread Aniko.Badzong
Title: FW: sql copy does not work







Hi 


I have a problem with the copy command. I need to write a Perl script where I copy the log files into the database.

If I use the copy following syntax in shell script it works, but I need to use it in Perl.


In shell script look like this and it works.

su - postgres -c "echo "\""copy test from '/data/20060227.out';"\"" | psql imsdb"


this is how it looks like in Perl:

system ("su - postgres -c \"echo \"\"\"copy test from \'/data/log/20060115.out\'\;\"\"\" | psql imsdb\""); 


I escape always the " but then I get the following error.

copy

sh:  | psql imsdb: not found



If I try the other way around there is always an error that role c does not exist

system ("su - postgres -c \"psql imsdb -c \"copy mss6n from '/data/20060227.out'\;\"");

psql: warning: extra command-line argument "copy" ignored

psql: FATAL:  role "-c" does not exist


If I try to use copy with the -c option I always get an error that role -c does not exist.

Anyone has any idea why?

I was searching in the knowledge database and docs for this error but I can not find anything.



Many thanks

Aniko