如何在 WHERE 子句中用动态日期替换固定日期?

How to replace a fixed date with dynamic date in WHERE clause?

select concat(CURRENT_DATE, ' ', '00:00:00+02:00')

returns "2020-07-14 00:00:00+02:00"

我可以将此结果复制粘贴到我的 WHERE 子句中:

where (xyz between timestamp with time zone '2020-06-01 00:00:00+02:00' 
and timestamp with time ZONE 2020-07-14 00:00:00+02:00

它有效,但如果我使用更动态的构造 concat(CURRENT_DATE, ' ', '00:00:00+02:00') 代替:

where (xyz between timestamp with time zone '2020-06-01 00:00:00+02:00' 
and timestamp with time ZONE concat(CURRENT_DATE, ' ', '00:00:00+02:00')

我收到一个语法错误:

ERROR: syntax error at or near "concat" LINE 57: ...6-01 00:00:00+02:00' and timestamp with time ZONE concat(CUR...

为什么第一个 WHERE 子句有效,但另一个无效,即使它以相同的格式打印相同的日期?

您可以使用 at time zone:

where xyz between ('2020-06-01'::date at time zone '+02:00') and (current_date at time zone '+02:00')