Re: [SQL] Re: Query is executing but giving error when using withshell scripting

Поиск
Список
Период
Сортировка
От Feike Steenbergen
Тема Re: [SQL] Re: Query is executing but giving error when using withshell scripting
Дата
Msg-id CAK_s-G1xOP5rcpZUcwTPhA+rCu=CWnqdPwA8L=Qcm5ezBhj+uA@mail.gmail.com
обсуждение исходный текст
Ответ на [SQL] Re: Query is executing but giving error when using with shellscripting  (srilinux <srilinux09@gmail.com>)
Список pgsql-sql


On 14 September 2017 at 17:58, srilinux <srilinux09@gmail.com> wrote:
> coba1=# select name from users where "Date" >current_date - 30;
>         name
> ---------------------
>  coba11
>  testCoba11
>



On 14 September 2017 at 18:27, srilinux <srilinux09@gmail.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.

В списке pgsql-sql по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: [SQL] Static variable inside PL/pgSQL (or) native C function
Следующее
От: Gourav Kumar
Дата:
Сообщение: [SQL] Get relation name form relids in postgresql