My team have their session timezones set differently, so to provide a consistent output, I thought I would utilise the following logic in views:
convert_timezone(current_setting('timezone'),'Australia/Melbourne',<timestamp>)
I have a view that also utilises the super datatype to simplify the extraction of data from json fields from a source system.
However testing a view prior to deployment, the following query with sub-select filter expressions fails:
create temp table test as
select * from <viewname>
where start_date between (select <date>) and (select <date>);
SQL Error [XX000]: ERROR: Query unsupported due to an internal error.
The following code illustrates the issue:
create or replace view sandpit.test as
select a.*, json_super."test" as test_val
from (
select convert_timezone('UTC','Australia/Melbourne',getdate()) as current_ts_AEST
,convert_timezone(current_setting('timezone'),'Australia/Melbourne',getdate()) as current_tz_AEST --comment out this line and both statements below succeed
,json_parse('{"test":1}') as json_super
) a
with no schema binding;
select * from sandpit.test where current_ts_AEST < getdate()::date + 1; --Works
select * from sandpit.test where current_ts_AEST < (select '2023-08-01'); --Fails with error
For anyone following this issue. AWS has confirmed it's an issue and Redshift engineering is working on a fix.