Reputation: 2865
I'm doing some tests, I've created the following table :
When I execute the following request :
SELECT date_trunc('month', my_date) FROM my_table;
it returns that :
I do understand it is a timestamp as stated by the PostGreSQL reference but I don't understand why it add these timezone and why there is that small variation between +01 or +02 ? How are they choosed ? is it a bug ?
Upvotes: 1
Views: 3510
Reputation: 12402
you're falling victim to date
beind implicitly cast to timestamp with thome zone
to enable the function call.
date_trunc is only defined for timestamp with time zone
and timestamp
inputs.
+01
+02
etc depends on your time locale's daylight saving rules.
if you want timestamp instead of timestamptz cast the date to timestamp first.
SELECT date_trunc('month', cast(my_date as timestamp)) FROM my_table
or you can create your own function which takes a date and returns a date.
create or replace function date_trunc(text,date) returns date language sql as
'select date_trunc($1, $2::timestamp)::date';
Upvotes: 2