conv.

All stories
TechActive today · day 2

Postgres AT TIME ZONE 'UTC' converts data type unexpectedly

Blog post clarifies that the SQL command converts timestamptz to plain timestamp, not just displaying UTC representation.

What to know

  • Postgres's AT TIME ZONE 'UTC' command converts a timestamptz column to a plain timestamp (without timezone), not just displaying the same data in UTC representation.
  • The distinction matters for data integrity: converting to timestamp without timezone loses timezone information unless the location is stored separately.
  • Discussion reveals broader debate about database timezone strategy: some favor UTC-only storage, others advocate IANA timezones or location-based approaches depending on use case.

The dispute Whether storing UTC-only is a best practice or loses critical information depends on whether location/timezone metadata is stored separately. · positions read across 22 posts and comments

many voices

AT TIME ZONE 'UTC' is a footgun because converting to timestamp loses timezone info.

  • “You loose information if you only save utc. If you save the location of the event separately that is fine, but also forces you to do the math manually.”

    good_live · Reddit ↗
some voices

Use IANA time zones as the default; they're unambiguous and handle conversion/arithmetic.

  • “I wish we'd just collectively start using IANA time zones as a default. Conversion and arithmetic are solved problems for them, and it's the least ambiguous format for stored dates.”

    FuckOnion · Reddit ↗
some voices

The choice depends on what data you're actually storing; no one-size-fits-all solution.

  • “I would say it always depends on what data you are actually saving.”

    good_live · Reddit ↗

tanin47 Blog post author

Postgres AT TIME ZONE 'UTC' converts data type unexpectedly
bookofrevenue.com

How it unfolded 4 developments, newest first · click a bar or a number to jump articlespostscomments

Peak 3 pieces in one hour at Sep 27, 2 AM; 28 pieces over 2 days (1 article · 5 posts · 22 comments) Sep 27, 1 AM — 1 piece · 1 post — Reddit 1Sep 27, 2 AM — 3 pieces · 3 comments — Reddit 3Sep 27, 3 AM — quietSep 27, 4 AM — quietSep 27, 5 AM — quietSep 27, 6 AM — 2 pieces · 1 article · 1 post — Hacker News 1, Newswires 1Sep 27, 7 AM — quietSep 27, 8 AM — quietSep 27, 9 AM — quietSep 27, 10 AM — quietSep 27, 11 AM — 1 piece · 1 comment — Reddit 1Sep 27, 12 PM — quietSep 27, 1 PM — quietSep 27, 2 PM — quietSep 27, 3 PM — quietSep 27, 4 PM — quietSep 27, 5 PM — quietSep 27, 6 PM — quietSep 27, 7 PM — quietSep 27, 8 PM — 1 piece · 1 comment — Reddit 1Sep 27, 9 PM — quietSep 27, 10 PM — quietSep 27, 11 PM — quietYesterday, 12 AM — quietYesterday, 1 AM — quietYesterday, 2 AM — quietYesterday, 3 AM — quietYesterday, 4 AM — 2 pieces · 2 posts — Mastodon 2Yesterday, 5 AM — 3 pieces · 3 comments — Hacker News 3Yesterday, 6 AM — 2 pieces · 2 comments — Hacker News 2Yesterday, 7 AM — 2 pieces · 1 post · 1 comment — Hacker News 1, Mastodon 1Yesterday, 8 AM — 1 piece · 1 comment — Hacker News 1Yesterday, 9 AM — quietYesterday, 10 AM — 2 pieces · 2 comments — Hacker News 2Yesterday, 11 AM — 1 piece · 1 comment — Hacker News 1Yesterday, 12 PM — 1 piece · 1 comment — Hacker News 1Yesterday, 1 PM — quietYesterday, 2 PM — 1 piece · 1 comment — Hacker News 1Yesterday, 3 PM — quietYesterday, 4 PM — 2 pieces · 2 comments — Hacker News 2Yesterday, 5 PM — quietYesterday, 6 PM — 1 piece · 1 comment — Hacker News 1Yesterday, 7 PM — quietYesterday, 8 PM — quietYesterday, 9 PM — quietYesterday, 10 PM — quietYesterday, 11 PM — 2 pieces · 2 comments — Hacker News 2Today, 12 AM — quietToday, 1 AM — quietToday, 2 AM — quiet 1–234
yesterdaynow · 3:08 AM ET
  1. 4

    Discussion spreads to Mastodon and social platforms

    The post gains further reach as it's shared across Mastodon and other platforms, with commentary on timezone handling and database best practices.

    • Unless I'm really misunderstanding, this is just "footgun of timestamp without timezone and implicit coercion"?The only purpose of the naive timestamp is to defer a necessary step of converting a sort of nominal prototype or template to a real moment on the timeline. Until you pin them down, they don't really represent moments.It's like having a…

      saltcuredHacker News12h agoview on Hacker News ↗
    2 more of the top 3 · 18 posts in this stretch
    • Yes. I know. I understand this. An Instant is measured against a reference point that has a known relationship to the world's time zones, so you can translate the instant's value to its representation in any time zone. A LocalDateTime has no reference point, so it has no relationship to time zones at all. (It's basically the same as timestamp with…

      Wyzard256r/programming1d agoview on r/programming ↗
    • The SQL standard is unfortunately really horrible when it comes to handling of time. The type `timestamp` is not a timestamp at all because it doesn't encode a unique point in time, it just stores a date and a time which has to be interpreted relative to a timezone. It should be called "datetime".Moving a Java Instant back and forth between a…

      ulrikrasmussenHacker News21h agoview on Hacker News ↗
    all of them →
  2. 3

    Post reaches Hacker News frontpage

    The article circulates on Hacker News under the headline 'Footguns with Postgres "at time zone 'UTC'"', generating discussion among database engineers.

    “I wish we'd just collectively start using IANA time zones as a default. Conversion and arithmetic are solved problems for them, and it's the least ambiguous format for stored dates.”
    — FuckOnion, Reddit commenter · source
    1. first by HN Frontpage, 1d ago

    • I wish we'd just collectively start using IANA time zones as a default. Conversion and arithmetic are solved problems for them, and it's the least ambiguous format for stored dates. Offsets are ephemeral whereas IANA time zones are built to last.

      FuckOnionr/programming1d agoview on r/programming ↗
  3. 2

    Author updates blog with clearer summary

    The blog post author modifies the article to add a summary at the top, explicitly stating that timestamptz AT TIME ZONE 'UTC' converts to timestamp without timezone.

    “timestamptz AT TIME ZONE 'UTC' gives us a timestamp without time zone i.e. timestamp, not a timestamptz. It converts the data type to timestamp without time zone.”
    — tanin47
    • > timestamptz AT TIME ZONE 'UTC' gives you the representation of a moment of time in the UTC time zone I modified the blog to be clearer with a summary at the top. To clarify: `timestamptz AT TIME ZONE 'UTC'` gives us a timestamp without time zone i.e. `timestamp`, not a `timestamptz`. It converts the data type to `timestamp without time zone`.

      tanin47r/programming2d agoview on r/programming ↗
    2 more of the top 3 · 3 posts in this stretch
    • You loose information if you only save utc. If you save the location of the event separately that is fine, but also forces you to do the math manually. I would say it always depends on what data you are actually saving.

      good_liver/programming2d agoview on r/programming ↗
    • The TLDR is actually: `AT TIME ZONE 'UTC'` converts the data type from `timestamp with timezone` to `timestamp without timezone`. I've modified the blog post to add the summary at the top!

      tanin47r/programming2d agoview on r/programming ↗
    all of them →
  4. 1

    Blog post details Postgres timezone conversion behavior

    A technical blog post explains how Postgres's AT TIME ZONE 'UTC' command works—specifically that it converts the data type from timestamptz to plain timestamp rather than just changing representation. The author clarifies the distinction in response to confusion about the feature's behavior.

What people are saying 14 voices from 1 site · best of 22 · verbatim