Lets say I have a timestamp with timezone stored in my PostgreSQL database. Something like this:
2003-04-12 04:05:06.814191 America/New_York
When reading this data, would the database return the adjusted time in GMT to standardize all timestamps read, or would it simply return it as is?
The reason I ask this question is I created a table with records, where each record had a timestamp column. I went on to provide different timezones for different records. When I queried this table, and tried ordering by the timestamp column, the timezone did not seem to have any effect on the ordering. Is this by design?
A sample of my results:
1954-06-27 08:44:01.963454 Asia/Baghdad
1954-06-27 08:44:01.963454 GMT
1954-06-27 08:44:01.963454 Europe/Paris
1954-06-27 08:44:01.963454 Asia/Baghdad
1954-06-27 08:44:01.963454 America/New_York
1954-06-27 08:44:01.963454 America/New_York
1954-06-27 08:44:01.963454 America/New_York
1954-06-27 08:44:01.963454 GMT
1954-06-27 08:44:01.963454 America/New_York
1954-06-27 08:44:01.963454 America/New_York
1954-06-27 08:44:01.963454 Europe/Paris
1954-06-27 08:44:01.963454 America/New_York
1954-06-27 08:44:01.963454 Asia/Dhaka
1954-06-27 08:44:01.963454 GMT
1954-06-27 08:44:01.963454 GMT
1954-06-27 08:44:01.963454 Asia/Damascus
1954-06-27 08:44:01.963454 GMT
1954-06-27 08:44:01.963454 Asia/Damascus
1954-06-27 08:44:01.963454 America/New_York
1954-06-27 08:44:01.963454 Asia/Dhaka
1954-06-27 08:44:01.963454 Asia/Baghdad
1954-06-27 08:44:01.963454 Europe/Paris
1954-06-27 08:44:01.963454 Europe/Paris
1954-06-27 08:44:01.963454 Asia/Baghdad
1954-06-27 08:44:01.963454 Asia/Baghdad
The date and time are the same for all these records, and the varying timezones had no effect on the ordering.
To make it more clear, I am actually storing these timestamps as strings in a JSONb column called data with a key of datetime, ie:
data = {
"datetime" : "2003-04-12 04:05:06.814191 America/New_York",
.....
}
During ordering and filtering, I'm casting it as a timestamp. Something like this:
"(data->>'datetime')::timestamp"
TIMEZONETZtype—its' just an instant in time. Can you show how you're inserting/selecting your example data? - teppictimestamp, that meanstimestamp without time zone, nottimestamp with time zone. - Wyzard