Unofficial Hacker News client - receive Push Notifications on replies.

What Changes When You Upgrade from PostgreSQL 18 to 19 (opens external site)

136 points by rgoomar 4 days ago | rishigoomar.com | 71 comments on HN | Vote on HN (opens Hacker News)

View full thread · View on Hacker News

Comment thread (37)

  1. Try storing datetimeoffset (ie datetime with time zone) in Postgres. It can’t.

    Also suppose you have a lastname and want to have case-insensitive search over it (prefix and equal).

    In MS SQL you just add an index. By the way, there is only one type to choose from (ignoring clustered or multicolumn) — it just works.

    In Postgres you needed to jump through effing hoops just for that until like 1-2 years ago when they finally added case-insensitive collation with prefix search support.

    —

    How people ignored such basic stuff for any CRUD app for years is beyond me.

    Replies (4)
    1. Fair points about SQL Server’s convenence, but Postgres has supported time zone aware timestamps and indexed case insensitive searches for decades…

      The original offset requires separate storage, and indexing requires a little more explicit configuration.

      I’d characterize these as design tradeoffs rather than missing CRUD functionality.

      Replies (3)
      1. But the timestamps are not time zone aware! It's just a query-time wrapper around a UTC timestamp, defaulting to input/output using the current session's default time zone.

        This makes it a giant footgun in practice, because it might seem to work at first glance. Until you discover that it is completely unfit for purpose in any kind of tz-aware application and returning garbage.

        "Timestamp with time zone" should not exist. It should've been an explicit UTC-zoned type, without any kind of automatic conversion.

        Replies (1)
        1. > Until you discover that it is completely unfit for purpose in any kind of tz-aware application and returning garbage.

          IME SQL standard should have been all DATETIME and TIMESTAMP are with TZ, in the sense that they aren't relative at the time they're stored.

          Now the absence of DatetimeOffset has never burned me in practice because I've never needed to know the historical offset, only the point in absolute time. And historical offsets can be derived from other sources since zones don't change often enough to justify duplicating that data in every historical value involving time.

      2. Timestamp with timezone should be in top-5 the most misleading names ever
      3. > indexed case insensitive searches for decades…

        Which is …? And prefix support is important (eg first few letters of a last name)

    2. Conversely, MS SQL doesn’t allow BRIN indexes for clustered row-store tables despite already having the code in the database engine for it!

      Every database engine has bizarre limitations that make no sense to me.

      I’ve noticed that a few other disgruntled DBAs have started fixing these issues up by throwing tokens at Postgres.

    3. timestamptz (with time zone) stores the times without time zone (in UTC), on the rationale that 'with time zone' means each read/write of that column will have a user supplied time zone..
      Replies (3)
      1. Timestampz discards the timezone and converts to utc, meaning it is a destructible operation — you cannot bring back the original.

        This may be important in many cases: for example antifraud where you want to store also what was literally on the user’s clock (including timezone) and show it later in reports and what have you

        Replies (4)
        1. I agree that the MSSQL timezoneoffset approach is the best.

          However the Postgres (and others) work-around is simply to add a LocalTimeZone field where necessary.

          Yeah, it's not as convenient, but it's a simple, effective, work-around.

          For me, this isn't the killer-app distinction that suggests choosing MSSQL over Postgres.

          Replies (1)
          1. > I agree that the MSSQL timezoneoffset approach is the best.

            It is not. A static offset is largely equivalent to a utc timestamp, and thus useless for any consideration of future event.

            If you’re concerned about the limited historical and auditing value, it’s not exactly difficult to just tack that information on in a second column, or create a custom type which you can even call datetimeoffset but hanging the entire thing on that edge case is nonsense.

            Hell, if you’re concerned about auditing events or fraud control you want a ton more data than just a timezone offset advertised by the client, and storing an entire timestamp just to keep that datum around is an unnecessary waste.

            Replies (2)
            1. Yes, the work-around is simple (as I said above.)

              A static offset however is not equivalent to storing as utc. Storing the local offset is objectively more information than not.

              But yes, the workaround is simple.

              Continue this thread (1 replies) →

            2. You may have a lot of dates. And thus would need a lot of “second” columns.

              Continue this thread (1 replies) →

        2. This kind of audit trail sounds like a "store a string" nail or hammer.
        3. Even worse: your future timestamps will be corrupted if the timezone definition ever changes!

          Your country abolishes DST? Good luck trying to fix that mess...

          Replies (1)
          1. Imagine some kind of assessment system (like tests / questionnaires); the only relevant “time” is during that assessment.

            You would not need to convert that time to some other time zone and what have you 3 years from now.

            For other stuff, of course, utc is enough.

            However it is just huge amount of cope trying to defend that you cannot store what ms sql allows you to.

            Replies (1)
            1. Pg can store it, either as an extra column or a custom type. DatetimeOffset isn't in the standard, which I think speaks to how niche the need is.

              Continue this thread (1 replies) →

        4. That's a problem only because your data model doesn't take into account how to make user supplied datetime work. Timestamp and the likes are not for user supplied data, datetime is. And if you are going to deal with it, you should store two dates: what the user said and what the datetime in utc is at the moment of recording. That gives you everything you will ever need: comparison between timezones, offsets regardless of timezones and a coherent user presentation.
          Replies (2)
          1. Dude, you literally have datetimeoffset in ms sql
            Replies (3)
            1. That's not SQL standard. Pg can provide similar functionality with custom types and functions, if it must be a single assignment and output.

              Continue this thread (1 replies) →

            2. Congratulations. MSSQL has some good features. Its cost, administrative overhead, and lack of available source make it an unacceptable option for a lot of people. Postgres also has lots of features that MSSQL does not have. Not sure why any of this is relevant in a post about differences in the new PG version.
            3. And? I'm questioning your data model, same problem will happen no matter your database, because now you have to consider DST and comparisons between timezones that are timezone sensitive. Meanwhile storing UTC and as user supplied it both gives you the most flexibility for any representation of date time that your application might need. Not counting that now you are shackled to a vendor like the sibling comment notes, because it's not standard sql
          2. Any solution that does not capture the timezone will be wrong sometimes. Your described solution falls on its face for any situation where an offset doesn't uniquely identify the timezone. For example, Arizona does not recognize daylight savings time, so sometimes it's got the same offset as Mountain Time, other times it has the same offset as Pacific Time.
      2. If it stores them in UTC, doesn't it store them with timezone? Whether what this timezone is is implied or not, there's a specific fixed timezone expected to be found in that column: UTC.
        Replies (1)
        1. Sadly, no.

          Time zones can change relative to UTC, e.g. the country Georgia in Europe.

          Daylight savings time (DST) can affect the offset from UTC as well and can vary based on location and can vary across UTC for the same location.

          Replies (1)
          1. >Time zones can change relative to UTC, e.g. the country Georgia in Europe.

            Yeah, but if you have the UTC time, you can calculate any local time at any point, using a tz lookup table of changes (since changes are not deterministic), right?

      3. Oddly enough, the offset isn't even enough information to truly describe the time zone. There might be a few different time zones that would have the same offset at a certain point in time. So the offset doesn't effectively communicate where the user is, what schedule (if any) they use for DST/summer time, and a bunch of other stuff. I'll admit that "2026-11-29T16:47:27-05:00" makes it pretty likely that the time zone is "America/New_York", but it's far from certain. I suppose it does at least let you do a timezone-aware truncation to a date, but it comes at the cost of making it more tricky to compare values with different offsets.
    4. > Try storing datetimeoffset

      Datetime+offset is virtually never useful to store. Almost always a mistake or at best unnecessary.

      You can use a composite type if you really want to, but it’s such a niche case I’m not surprised there’s not a dedicated feature.

      > case-insensitive search over it (prefix and equal).

      Has worked for decades, since 2003.

        CREATE INDEX ON person (lower(last_name) text_patten_ops);
      
        SELECT *
        FROM person
        WHERE lower(last_name) LIKE ‘smi%’;
      Replies (1)
      1. > as worked for decades, since 2003.

        My man, suppose you use an ORM. With your approach you must not forget to:

        1. Lower the column

        2. Lower the search term

        … every single time you write a query.

        And god forbid you fuck this up even once. This is not how reliable systems are done

        Replies (2)
        1. I’m fairly positive you could teach the ORM to do that fairly easily in most ORMs. I’d be much more concerned by the non-ORM case.

          But also isn’t the correct answer to set your collation if you actually need it across the board

        2. There is a whole feature of postgres and SQL standards called "collations" that I think you may be ignoring here..?

          A collation can specialize how comparison and ordering work. In postgres this would also affect the pattern matching operators. I think there have been improvements here over the recent versions, where a "non-deterministic" collation (of which case-insensitivity is an example) is supported by pattern matchers when it wouldn't in older versions.

          You can define a column with a custom collation to override the default for the column type. You can also define a domain type with a custom collation, and use that domain for column definitions, so you don't need to set the collation explicitly in every column definition. E.g. you could define a "citext" domain over "text" that adds the case-insensitivity but otherwise stores text.