From: | Feike Steenbergen <feikesteenbergen(at)gmail(dot)com> |
---|---|
To: | srilinux <srilinux09(at)gmail(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Re: Query is executing but giving error when using with shell scripting |
Date: | 2017-10-05 06:01:45 |
Message-ID: | CAK_s-G1xOP5rcpZUcwTPhA+rCu=CWnqdPwA8L=Qcm5ezBhj+uA@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 14 September 2017 at 17:58, srilinux <srilinux09(at)gmail(dot)com> wrote:
> coba1=# select name from users where "Date" >current_date - 30;
> name
> ---------------------
> coba11
> testCoba11
>
On 14 September 2017 at 18:27, srilinux <srilinux09(at)gmail(dot)com> wrote:
>
> Did not help
>
> /usr/bin/psql -U postgres -d coba1 -c "select name from users where
Date
> > current_date - 30;"`
>
> same error
>
It looks like you have a column named Date, capitalized. Which means you
actually need to surround your column name with double quotes.
Your shell (bash?) is removing the double quotes, so either escape your
double quotes:
/usr/bin/psql -U postgres -d coba1 -c "select name from users where
\"Date\" > current_date - 30;"
Or use single quotes to surround the query, which also prevents your shell
from removing the double quotes.
/usr/bin/psql -U postgres -d coba1 -c 'select name from users where
"Date" > current_date - 30;'
You may also want to consider not using capitalized column names, as it
would remove the need to quote column names altogether.
From | Date | Subject | |
---|---|---|---|
Next Message | Gourav Kumar | 2017-10-05 18:17:36 | Get relation name form relids in postgresql |
Previous Message | Pavel Stehule | 2017-10-03 17:25:56 | Re: Static variable inside PL/pgSQL (or) native C function |