Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1miPAx-0001D7-MT for pgsql-general@arkaria.postgresql.org; Wed, 03 Nov 2021 22:56:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1miPAv-0008PV-6u for pgsql-general@arkaria.postgresql.org; Wed, 03 Nov 2021 22:56:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1miPAu-0008PL-SU for pgsql-general@lists.postgresql.org; Wed, 03 Nov 2021 22:56:08 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1miPAp-0005hu-Gx for pgsql-general@lists.postgresql.org; Wed, 03 Nov 2021 22:56:07 +0000 Received: by mail-pl1-x635.google.com with SMTP id u17so4026519plg.9 for ; Wed, 03 Nov 2021 15:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yugabyte.com; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=cbY1iIzBURd0msFYn6Vaqcv9/79zZh3SF8C0Rf+vMD8=; b=aCXA/MNiDjXOv1a/LS4SR9cncVTmsrF84Tvv0A1Ksx2eyOnKbKEiYklC2uzd7Ecd3Y JTuOoYFtTNnjOojCDDGMgesiZPl72M23QCl0xo8LRFappbd1UYAgi1tqD7LeHZ+JxX72 DqKEEOC5ChKTiIlUsoxhR6+D1TebTQ6nupxbo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=cbY1iIzBURd0msFYn6Vaqcv9/79zZh3SF8C0Rf+vMD8=; b=Ib8cxF1ro8foykYZcVuv4O6UnE5xvKFea+NAungBsq1FKX5uPjp2VSuM8Y+BplunGQ 5I+2xM3I0NZeTvDHdzA5yaZaguiKJ5CkMDxymnfpnwIQG0cy1pTyv+/kafYtzNRFxFXa Vple94RtTb3LuET2wu1l2UQbgsXaCXQ7PXD+Qrkz/xxC0v6D29lCVHLzYY6y6vMpsNAx x5B+OGejy8e3h5Pj0cb++j8HTbcLq8/mrq6r6+LTsI/8osh2KCINk3AqVM9jbjANLAJa Tbgix5WNneJ3WEH/PjwsIIPBFed+as7Gyz7eyPx4pc60KLhzQv0anQuW4K6N9Io3UZ+o VF7A== X-Gm-Message-State: AOAM531kirTg6uwwteKHguJ7gtIzXCxDojEDrnVyTAzBuZrCIX5SwbUP pGkg+VsZ8gWBjvQoKReHbi/pJA== X-Google-Smtp-Source: ABdhPJwwWvm+xmUUSMU2s0PdDaxz4B/wgH4OHB1D5ej7RNQOhZO1oiP1TFnF4oz0U1HS72RhP0zA9Q== X-Received: by 2002:a17:90a:6b4d:: with SMTP id x13mr17997001pjl.208.1635980162294; Wed, 03 Nov 2021 15:56:02 -0700 (PDT) Received: from smtpclient.apple ([2601:646:101:7fda:4139:aa7a:42b8:d973]) by smtp.gmail.com with ESMTPSA id oo9sm2737460pjb.53.2021.11.03.15.56.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Nov 2021 15:56:01 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: to_date() and to_timestamp() with negative years From: Bryn Llewellyn In-Reply-To: <265331.1635978234@sss.pgh.pa.us> Date: Wed, 3 Nov 2021 15:56:00 -0700 Cc: Adrian Klaver , pgsql-general list Content-Transfer-Encoding: quoted-printable Message-Id: <745E3531-6791-4964-AF68-BC82FC2EC864@yugabyte.com> References: <138332.1635962086@sss.pgh.pa.us> <08E63AD5-8E6D-4140-AE1C-9DC22324A287@yugabyte.com> <72204b8f-41b2-0004-b09b-842f8c57477f@aklaver.com> <0B75398B-91CC-4074-B77A-390AA157685B@yugabyte.com> <265331.1635978234@sss.pgh.pa.us> To: Tom Lane PostgreSQL X-Mailer: Apple Mail (2.3654.120.0.1.13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > tgl@sss.pgh.pa.us wrote: >=20 > Adrian Klaver writes: >> Haven't had time to work through what the above is actually doing. >=20 > I think the first two are explained by 489c9c340: >=20 > Also, arrange for the combination of a negative year and an > explicit "BC" marker to cancel out and produce AD. This is how > the negative-century case works, so it seems sane to do likewise. >=20 > The last two look like a parsing issue: with no field separator (nope, = the space doesn't count), the code is taking the dash as a field = separator. Thanks, Adrian, for trying those tests. So if PG is aiming for one = consistent story for years that are less than one, in all three APIs = (to_date() and its cousins, make_timestamp[tz](), and text-to-date-time = typecasts), then work still remains. The parsing problem seems to be a separable annoyance. I assume that = Tom=E2=80=99s "nope, the space doesn't count=E2=80=9D is a narrow = comment on this corner of the implementation. It definitely counts here: select to_date('12345 01 01', 'YYYY MM DD'); And you have to have some kind of separator between the years substring = and the adjacent one(s) even to succeed with years that have more than = four digits. Another usage note stresses that while this is OK: select to_date('12340101', 'YYYYMMDD'); this isn't: select to_date('123450101', 'YYYYMMDD'); and nor is anything else that you might dream up that does not have a = separator as mentioned above. Tom asked about Oracle Database. I have a still-working Version 18.0 in = a VM on my laptop. The query can't be so terse there because there's no = implicit typecast from date to text. And there's the famous annoyance of = "dual". I tried this first: select to_char(to_date('1234/01/01', 'YYYY/MM/DD'), 'YYYY/MM/DD') from = dual; It gets the same output back as the input you gave. So far so good. Then = I changed the input to '-1234/01/01'. It caused this error: ORA-01841: (full) year must be between -4713 and +9999, and not be 0 So it seems that Oracle Database has its own problems. But at least the = wording "must=E2=80=A6 not be 0" is clear=E2=80=94and not what PG wants = to support.