I never use CURRENT_TIME
. It returns the type time with time zone
, the use of which is discouraged in the Postgres manual because it's an inherently broken construct. The type (and the function CURRENT_TIME
) are only supported because standard SQL sadly defined them this way. See:
LCOALTIME
(returning timestamp
) makes more sense. But you can just use now()
(= CURRENT_TIMESTAMP
) for everything. Local time always depends on the current time zone setting of the session anyway. See:
Of course, you can cast timestamp
or timstamptz
to time
:
To round to full seconds:
INSERT INTO my_tbl(my_time_col)
VALUES (LOCALTIME::time(0)::time);
To truncate to seconds or minutes, ...
date_trunc('second', LOCALTIMESTAMP)::time
date_trunc('minute', LOCALTIMESTAMP)::time
This is equivalent:
date_trunc('second', LOCALTIME)::time
date_trunc('minute', LOCALTIME)::time
The expression date_trunc('second', LOCALTIME)
returns interval
, so the cast to time
may or may not be needed. In an INSERT
writing to a time
column, the type is coerced automatically.
date_trunc('second', LOCALTIMESTAMP)
returns timestamp
. The explicit cast to time
may still be optional for the same reason.
Related: