This requires understanding first. I wrote an exhaustive answer on how PostgreSQL handles timestamps and time zones here:
Ignoring Time Zones in Rails and PostgreSQL
You cannot “not have” a time zone. You can work with the timestamp [without time zone]
, but you will still have the time zone in your client.
Your expression:
When I inserted a row using timestamp without time zone
(!) Using the CURRENT_TIMESTAMP
function ...
is a contradiction in adjecto . CURRENT_TIMESTAMP
returns a timestamp with time zone
(!). If you just threw it (or forced it) into the timestamp [without time zone]
, the timestamp [without time zone]
offset is truncated instead of applied. You get local time (regardless of the current time zone of the session) instead of UTC. Consider:
SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC' ,CURRENT_TIMESTAMP::timestamp
If your local time zone is not "UTC" or something like "London", the two expressions return different values.
If you want to keep the literal value that you see in your time zone, use one of the following options:
SELECT CURRENT_TIMESTAMP::timestamp ,now()::timestamp ,LOCALTIMESTAMP;
If you want to save the point in time, since it will be displayed in UTC, use one of the following options:
SELECT CURRENT_TIMESTAMP AT TIME ZONE 'UTC' ,now() AT TIME ZONE 'UTC;
source share