I'm quite newbie and although I've spent some hours already to google up a solution I still failing to resolve this issue - hope someone can help me out, please!
I'm trying to use while loop in bash with a postgresql query which would return me an integer for each date between 2018-01-01 and 2018-03-31. With my current query I'm getting the following error in bash:
"HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
ERROR: operator does not exist: date = integer
LINE 8: WHERE event_date=2018-01-02"
And the way I've tried to run the loop (scrip via mcedit) is:
#!/usr/bin/env bash
d=2018-01-01
while [ "$d" != 2018-04-01 ]; do.
psql -U dataguy -d postgres -c"
SELECT event_date, COUNT(DISTINCT(id)) as daily_active_users FROM
(SELECT event_type, country, id, CAST(NULL as INT) AS price, event_date FROM returners
UNION ALL
SELECT event_type, NULL AS country, id, CAST(NULL as INT) AS price, event_date FROM sub
UNION ALL
SELECT event_type, NULL AS country, id, price, event_date FROM buy) AS returners_sub_buy
WHERE event_date=$d
GROUP BY event_date;"
d=$(date -I -d "$d 1 day")
done
Any recommendation, advice or hint is greatly appreciated!
CodePudding user response:
Arguments usually need to be quoted, like
WHERE event_date='2018-01-02'