Shell script with sql script error

Hi All

when I execute from psql prompt, I get the result, when I try to automate
using a shell script, the query is not working

# `/usr/bin/psql -U postgres  -d coba1 -c  "select name from users where 
"Date" > current_date - 30;"` 

ERROR: column "Date" does not exist
LINE 1: select name from users where Date >current_...

========

works below

                                      ^ 
 sudo -u postgres psql 

psql (9.4.5)
Type "help" for help.

postgres=# \connect coba1 

You are now connected to database "coba1" as user "postgres".

coba1=# select name from users where "Date" >current_date - 30; 
        name 
--------------------- 
 coba11 
 testCoba11 

You have to escape quotes when you put them inside quotes, like \"

1 Like

HI All

Thanks for looking at this .

I have solved this by using the following format

#!/bin/sh

dbname="test"
username="test"
psql $dbname $username << EOF
SELECT * FROM test;
EOF