在 bash + postgresql 日期中循环 |运算符不存在:日期 = 整数

While loop in bash + postgresql date | operator does not exist: date = integer

我是新手,虽然我已经花了几个小时 google 找到解决方案,但我仍然无法解决这个问题 - 希望有人能帮助我!

我正在尝试在 bash 中使用 while 循环和 postgresql 查询,这将 return 我为 2018-01-01 和 2018-03-31 之间的每个日期计算一个整数。 在我当前的查询中,我在 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"

我尝试 运行 循环的方式(通过 mcedit 编写)是:


#!/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

非常感谢任何建议、建议或提示!

参数通常需要引用,比如

WHERE event_date='2018-01-02'