I am trying to query data from my postgresql database using pd.read_sql. There are timestamptz columns, with a combination of dates which have DST and some which don't. The dates which have a DST offset are being read in correctly, however those without a DST offset are being read as NaT.
All columns shown are of the same type, timestamptz
Example A - smart_departure has no DST offset
Queried using DBeaver
wtt_arrival | wtt_pass | wtt_departure | smart_arrival | smart_pass | smart_departure |
---|---|---|---|---|---|
NULL | NULL | 1970-01-01 08:23:00.000 +0100 | NULL | NULL | 2022-01-14 08:23:03.000 +0000 |
Queried using pd.read_sql ( for example pd.read_sql('select * from database', con=engine)
)
wtt_arrival | wtt_pass | wtt_departure | smart_arrival | smart_pass | smart_departure |
---|---|---|---|---|---|
None | None | 1970-01-01 07:23:00+00:00 | None | None | NaT |
Query by retrieving value directly (suggested by Gord Thompson below)
(None, None, datetime.datetime(1970, 1, 1, 7, 23, tzinfo=datetime.timezone.utc), None, None, None)
Queried using psql (suggested by Adrian Klaver)
wtt_arrival | wtt_pass | wtt_departure | smart_arrival | smart_pass | smart_departure |
---|---|---|---|---|---|
1970-01-01 07:23:00+00 |
Example B - smart_arrival has DST offset
Queried using DBeaver
wtt_arrival | wtt_pass | wtt_departure | smart_arrival | smart_pass | smart_departure |
---|---|---|---|---|---|
1970-01-01 15:49:00.000 +0100 | NULL | NULL | 2022-10-14 15:47:27.000 +0100 | NULL | NULL |
Queried using pd.read_sql
wtt_arrival | wtt_pass | wtt_departure | smart_arrival | smart_pass | smart_departure |
---|---|---|---|---|---|
1970-01-01 14:49:00+00:00 | None | None | 2022-10-14 14:47:27+00:00 | None | None |
Query by retrieving value directly (suggested by Gord Thompson below)
(datetime.datetime(1970, 1, 1, 14, 49, tzinfo=datetime.timezone.utc), None, None, datetime.datetime(2022, 10, 14, 14, 47, 27, tzinfo=datetime.timezone.utc), None, None)
Queried using psql (suggested by Adrian Klaver)
wtt_arrival | wtt_pass | wtt_departure | smart_arrival | smart_pass | smart_departure |
---|---|---|---|---|---|
1970-01-01 14:49:00+00 | 2022-10-14 14:47:27+00 |
Results of running show search_path and \d *.scheduled_and_actual_timings
timetabletooldev=> \d *.scheduled_and_actual_timings
View "public.scheduled_and_actual_timings"
Column | Type | Collation | Nullable | Default
----------------------+--------------------------+-----------+----------+---------
wtt_arrival | timestamp with time zone | | |
wtt_pass | timestamp with time zone | | |
wtt_departure | timestamp with time zone | | |
smart_arrival | timestamp with time zone | | |
smart_pass | timestamp with time zone | | |
smart_departure | timestamp with time zone | | |
timetabletooldev=> show search_path;
search_path
-----------------
"$user", public
(1 row)