dbTalk Databases Forums  

pgsql -c in bash shell script quote problem

comp.databases.postgresql comp.databases.postgresql


Discuss pgsql -c in bash shell script quote problem in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
luislupe@gmail.com
 
Posts: n/a

Default pgsql -c in bash shell script quote problem - 09-05-2007 , 09:35 AM






Hi,

I want to automate a task to copy values to a table.

The shell script is this (simple form):
psql -U postgres -d sedait_db -c '
COPY dp_calc_temp
(
ano
)
FROM \'/usr/local/pgsql/home/dw/iva_dp/calculados/
dp_calculados_juntos.csv\' WITH CSV ; '

The problem is that I have to use ' to delimit the entire psql
command, but ' is also required to for the file reference.

I tried to escape ' with \', as in the example, but I get as a
response:
unexpected EOF while liiking for matching `''
syntax error: unexpected end of file

If I try no \ escaping, I get a syntax error near "/"

Also tried do use double ', but to no avail.

I even tried $/usr/...$, but didn't make it.

How can this be solved?


Luis


Reply With Quote
  #2  
Old   
sircco
 
Posts: n/a

Default Re: pgsql -c in bash shell script quote problem - 09-05-2007 , 09:56 AM






On 2007-09-05, luislupe (AT) gmail (DOT) com <luislupe (AT) gmail (DOT) com> wrote:
Quote:
Hi,

I want to automate a task to copy values to a table.

The shell script is this (simple form):
psql -U postgres -d sedait_db -c '
COPY dp_calc_temp
(
ano
)
FROM \'/usr/local/pgsql/home/dw/iva_dp/calculados/
dp_calculados_juntos.csv\' WITH CSV ; '

The problem is that I have to use ' to delimit the entire psql
command, but ' is also required to for the file reference.

I tried to escape ' with \', as in the example, but I get as a
response:
unexpected EOF while liiking for matching `''
syntax error: unexpected end of file

If I try no \ escaping, I get a syntax error near "/"

Also tried do use double ', but to no avail.

I even tried $/usr/...$, but didn't make it.

How can this be solved?


Luis

Hi,

write your script in file and then psql .... -f file

rgds,
d.


Reply With Quote
  #3  
Old   
luislupe@gmail.com
 
Posts: n/a

Default Re: pgsql -c in bash shell script quote problem - 09-05-2007 , 10:30 AM



On Sep 5, 3:56 pm, sircco <sir... (AT) online (DOT) hr> wrote:
Quote:
On 2007-09-05, luisl... (AT) gmail (DOT) com <luisl... (AT) gmail (DOT) com> wrote:

Hi,

I want to automate a task to copy values to a table.

The shell script is this (simple form):
psql -U postgres -d sedait_db -c '
COPY dp_calc_temp
(
ano
)
FROM \'/usr/local/pgsql/home/dw/iva_dp/calculados/
dp_calculados_juntos.csv\' WITH CSV ; '

The problem is that I have to use ' to delimit the entire psql
command, but ' is also required to for the file reference.

I tried to escape ' with \', as in the example, but I get as a
response:
unexpected EOF while liiking for matching `''
syntax error: unexpected end of file

If I try no \ escaping, I get a syntax error near "/"

Also tried do use double ', but to no avail.

I even tried $/usr/...$, but didn't make it.

How can this be solved?

Luis

Hi,

write your script in file and then psql .... -f file

rgds,
d.
Thank you! You saved my day, although this way there is some
flexibility lost, for example in assigning variable names to files.

Luis



Reply With Quote
  #4  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: pgsql -c in bash shell script quote problem - 09-05-2007 , 11:22 AM



luislupe (AT) gmail (DOT) com <luislupe (AT) gmail (DOT) com> wrote:
Quote:
I want to automate a task to copy values to a table.

The shell script is this (simple form):
psql -U postgres -d sedait_db -c '
COPY dp_calc_temp
(
ano
)
FROM \'/usr/local/pgsql/home/dw/iva_dp/calculados/
dp_calculados_juntos.csv\' WITH CSV ; '

The problem is that I have to use ' to delimit the entire psql
command, but ' is also required to for the file reference.

I tried to escape ' with \', as in the example, but I get as a
response:
unexpected EOF while liiking for matching `''
syntax error: unexpected end of file

If I try no \ escaping, I get a syntax error near "/"

Also tried do use double ', but to no avail.

I even tried $/usr/...$, but didn't make it.
What keeps you from using double quotes?

psql ... -c "COPY .... FROM 'filename'"

Yours,
Laurenz Albe


Reply With Quote
  #5  
Old   
Jurgen Haan
 
Posts: n/a

Default Re: pgsql -c in bash shell script quote problem - 10-12-2007 , 09:40 AM



luislupe (AT) gmail (DOT) com wrote:

Quote:
I tried to escape ' with \', as in the example, but I get as a
response:
unexpected EOF while liiking for matching `''
syntax error: unexpected end of file
You can only escape and use shell variables between double quotes, not
between single quotes. Best to use double quotes anyway,


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.