agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedQuery is executing but giving error when using with shell scripting
4+ messages / 3 participants
[nested] [flat]
* Query is executing but giving error when using with shell scripting
@ 2017-09-14 15:58 srilinux <srilinux09@gmail.com>
2017-09-14 16:21 ` Re: Query is executing but giving error when using with shell scripting Andreas Kretschmer <andreas@a-kretschmer.de>
0 siblings, 1 reply; 4+ messages in thread
From: srilinux @ 2017-09-14 15:58 UTC (permalink / raw)
To: pgsql-sql
Please suggest what is giving error here
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
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-sql-f2142323.html
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Query is executing but giving error when using with shell scripting
2017-09-14 15:58 Query is executing but giving error when using with shell scripting srilinux <srilinux09@gmail.com>
@ 2017-09-14 16:21 ` Andreas Kretschmer <andreas@a-kretschmer.de>
2017-09-14 16:27 ` Re: Query is executing but giving error when using with shell scripting srilinux <srilinux09@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Kretschmer @ 2017-09-14 16:21 UTC (permalink / raw)
To: pgsql-sql@postgresql.org,srilinux <srilinux09@gmail.com>
On 14 September 2017 17:58:07 GMT+02:00, srilinux <srilinux09@gmail.com> wrote:
>Please suggest what is giving error here
>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_...
>
>
>========
>
Remove the " from Date, or write "date". It is just a quoting-problem.
Regards, Andreas
--
2ndQuadrant - The PostgreSQL Support Company
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Query is executing but giving error when using with shell scripting
2017-09-14 15:58 Query is executing but giving error when using with shell scripting srilinux <srilinux09@gmail.com>
2017-09-14 16:21 ` Re: Query is executing but giving error when using with shell scripting Andreas Kretschmer <andreas@a-kretschmer.de>
@ 2017-09-14 16:27 ` srilinux <srilinux09@gmail.com>
2017-10-05 06:01 ` Re: Re: Query is executing but giving error when using with shell scripting Feike Steenbergen <feikesteenbergen@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: srilinux @ 2017-09-14 16:27 UTC (permalink / raw)
To: pgsql-sql
Did not help
/usr/bin/psql -U postgres -d coba1 -c "select name from users where Date
> current_date - 30;"`
same error
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-sql-f2142323.html
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Re: Query is executing but giving error when using with shell scripting
2017-09-14 15:58 Query is executing but giving error when using with shell scripting srilinux <srilinux09@gmail.com>
2017-09-14 16:21 ` Re: Query is executing but giving error when using with shell scripting Andreas Kretschmer <andreas@a-kretschmer.de>
2017-09-14 16:27 ` Re: Query is executing but giving error when using with shell scripting srilinux <srilinux09@gmail.com>
@ 2017-10-05 06:01 ` Feike Steenbergen <feikesteenbergen@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: Feike Steenbergen @ 2017-10-05 06:01 UTC (permalink / raw)
To: srilinux <srilinux09@gmail.com>; +Cc: 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.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2017-10-05 06:01 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-09-14 15:58 Query is executing but giving error when using with shell scripting srilinux <srilinux09@gmail.com>
2017-09-14 16:21 ` Andreas Kretschmer <andreas@a-kretschmer.de>
2017-09-14 16:27 ` srilinux <srilinux09@gmail.com>
2017-10-05 06:01 ` Feike Steenbergen <feikesteenbergen@gmail.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox