0

I have data stored in a timestamp with timezone column (timestamptz) in UTC.

I want to query in a different timezone (Australia/Sydney +10) but retain the timezone

SELECT 
    '2022-05-04 14:00:01.546+00'::timestamp AT time zone 'UTC',
    timezone('Australia/Sydney', '2022-05-04 14:00:01.546+00'::timestamp AT time zone 'UTC')
;

This returns:

"2022-05-04 14:00:01.546+00" timestamp with time zone

"2022-05-05 00:00:01.546" timestamp without time zone

What I want is:

"2022-05-05 00:00:01.546+10" timestamp with time zone

i.e. convert from +00 to +10 and retain the time zone. I keep finding examples that convert to local time without the timezone info. I'm trying to map to a pyarrow.Table and want to infer the correct type timestamp[ns, tz=Australia/Sydney] rather than timestamp[ns, tz=UTC]

Edit: To make it clearer I've tried the following:

select
    ts,
    timezone('Australia/Sydney', ts),
    ts at time zone 'Australia/Sydney'
from timeseries
limit 1

enter image description here

4
  • I think all you need is the_column at time zone 'Australia/Sydney' Commented Mar 7, 2023 at 7:14
  • That gives me the same as timezone('Australia/Sydney', the_column) - a timestamp without timezone of value "2022-05-05 00:00:01.546". At least when I run it in pgAdmin Commented Mar 7, 2023 at 8:15
  • That will most certainly return a timestamp WITH time zone Commented Mar 7, 2023 at 8:20
  • That what I was expecting - but I've pasted in the output from pdAdmin and its a localised naive timezone from what I can see. Commented Mar 7, 2023 at 8:22

1 Answer 1

1

The way PostgreSQL works, the only way to get the output 2022-05-05 00:00:01.546+10 is to set the timezone parameter to a time zone with that UTC offset:

SET timezone = 'Australia/Sydney';
Sign up to request clarification or add additional context in comments.

1 Comment

Ah right, yes that works. I'm not sure I can send multiple statements using connectorx but thanks anyway. I think I might use UTC and convert the pyarrow.Table column on the client.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.