Postgres automatically converting date and timestamp fields to timestamptz
I have a view which is built on a CTE.
create or replace view viewname
as
WITH all_dates AS
(
SELECT generate_series
(
( SELECT min(date_trunc('day'::text, problem_time))::date AS min
FROM tablename)
, now()::date
, '1 day'::interval
)::date AS date_id
)
, ..... rest of view
When the command is executed, Postgres is generating the view as
create or replace viewname
as
WITH all_dates AS
(
SELECT generate_series
(
(
( SELECT min(date_trunc('day'::text,problem_time))::date AS min
FROM tablename))::timestamp with time zone
, now()::date::timestamp with time zone
, '1 day'::interval)::date AS date_id
)
, ..... rest of view
This continues further down the CTE structure when doing filters with timestamp fields, the value being compared to is converted to timestamptz.
Where I wrote
where response >= reference
-- response is a timestamp type
-- reference is a timestamp type from some other preceding query
Postgres is converting to
where response >= reference::timestamp with time zone
My questions are why is this happening and how can I prevent it?