Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t1KEd-00FjKz-2X for pgsql-general@arkaria.postgresql.org; Thu, 17 Oct 2024 06:43:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t1KEb-00Ha3t-9a for pgsql-general@arkaria.postgresql.org; Thu, 17 Oct 2024 06:43:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t1KEa-00Ha1e-TH for pgsql-general@lists.postgresql.org; Thu, 17 Oct 2024 06:43:45 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t1KEY-001UGP-Ug for pgsql-general@lists.postgresql.org; Thu, 17 Oct 2024 06:43:44 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-5c9fd6dae47so377000a12.2 for ; Wed, 16 Oct 2024 23:43:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729147421; x=1729752221; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=EdCYCYS7zxCGFKK5zQZy8KZaFZ2Yqz6rMj3SpGFO+a0=; b=cCUdpzZjbB0JxSdOLRPzWRJS2Gr4xbd8KPupEF8Yi9HIsIkr6NeytmjH8/L5Aj0YCZ Yb9ub74KfWiICrcc65xDdyFfcOS1nWrZpiceb6ZSxizdo+t3tFmCA4BFYhg2aEAQAS/t +sgRZUk4Jojw0oinj60tGM+mr5Kgabodc1Od9QR4yhkYppiPPzo/lsNcmeJwqf5bo0Ae JQmFRJWN7m9W0ikr6mFCDI5H5LFoPdFCP5pnD1xNQwd6Ek/T//Tr3l2/nBwD4jn8fTB8 F+jik4UcTWqkvP+rlX/BJdsUuiwcobAf4ojVC9/NutrfwtTJxIVJFYwclRfizbVmVPvh +qIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729147421; x=1729752221; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EdCYCYS7zxCGFKK5zQZy8KZaFZ2Yqz6rMj3SpGFO+a0=; b=CmDOkXuSifWQ2m16xNLHRg35pAbPbLS/Nrpji16rHbb4h0pCgdRY2K/h0WhA0UXy/J js6sO5yxCjw2FLGxSQBZ0Z0ZaMTj1xJsaU09miWtBYkHsXETutyupk8EVwYBCITCP2l9 Ub/1kbITyzXnDQMXAnHkaB8MLnwMA+NZlsbr64vuzohKyrYKzmIiG4HYGzzZy7p9ulTz JD1uQrcaEo2heqMUfqRNq46CFC/Yl4X3c2DO5bv1qouwFItf4jMr4pXUoDqCeHHQqpIo oprKwIf7n5ysSPC264gsnIxx1sIlhK2ZlF8aOm069YOMO1XT2GbCEKWs0+C07xj4tC/M AoJg== X-Forwarded-Encrypted: i=1; AJvYcCVm1Sc9Tv6N2VqfXbUGodMxi4Twtkf9CnY97omfTIvGOgSBIxQxI5FoV3zSsn/IVStY6W89z5jPmFAhaeaE@lists.postgresql.org X-Gm-Message-State: AOJu0Yzp2Z5GFflC3NALz69MgX2lXRg1g2tp868W64Ak7GokwAdX6c8l D0Y88nnW+SW56KcuYFuUMQ1yAfMzdVdlvpT0f1Qjtjjo2oVueY4UfYEo0EdR2giser+G1jyOzs+ uxF3ONEF9YXir31xwhts3xTKcx5A= X-Google-Smtp-Source: AGHT+IEayKcmbefXbrTa9Ngoi/Um31YIiyEXOsLnf4MPgnC8PpkINiUEt9p6jiBNq0q5AwbKn6HQz1pYreCR3DqL6a0= X-Received: by 2002:a05:6402:51cb:b0:5c9:27de:6e73 with SMTP id 4fb4d7f45d1cf-5c95abf2e6cmr14222102a12.5.1729147420855; Wed, 16 Oct 2024 23:43:40 -0700 (PDT) MIME-Version: 1.0 References: <0af9ebc00dca444cbd3c5e07752bc5f9@oeaw.ac.at> <505768.1729125372@sss.pgh.pa.us> In-Reply-To: <505768.1729125372@sss.pgh.pa.us> From: Asad Ali Date: Thu, 17 Oct 2024 11:43:28 +0500 Message-ID: Subject: Re: Support for dates before 4713 BC To: Tom Lane Cc: David Rowley , "Richards, Nina" , "Watzinger, Alexander" , "pgsql-general@lists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000c8d5940624a68133" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000c8d5940624a68133 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Nina Richards, Instead of using PostgreSQL's DATE or TIMESTAMP types, you can store years as NUMERIC or BIGINT values. You can manually represent dates before 4713 BC and build custom functions for date operations like addition, subtraction, or comparison. To facilitate comparisons or operations on your custom dates (BC/AD), you can create user-defined functions in PostgreSQL for adding, subtracting, or comparing dates. Best Regards, Asad Ali On Thu, Oct 17, 2024 at 5:36=E2=80=AFAM Tom Lane wrote: > David Rowley writes: > > It's by no means a trivial thing to do, but it is possible to > > implement new types in PostgreSQL [1]. If you invented your own type, > > you could significantly widen the upper and lower bounds when compared > > with the standard date type. > > However, you'd then have to reimplement some large fraction of the > existing datetime support to have something useful. > > We're already inventing freely to use the Gregorian calendar for > millenia before Pope Gregory lived, so I see no conceptual argument > not to extend that back even further. > > IIRC the stumbling block for not going back past Julian day 0 was > uncertainty about whether the date2j and j2date algorithms behave > correctly for negative Julian dates --- which at the time was > compounded by the fact that C90 was vague about the rounding direction > for integer division with negative inputs. Now that we assume C99 > with its well-defined rule for that, at least some of the uncertainty > is gone. Somebody would still have to study that code and either > prove that it's OK or correct it. And then there would be a > nontrivial amount of effort to work outwards and fix anything else > that is assuming that limitation. So it would take somebody with > considerable motivation to make it happen, but if such a somebody were > to appear with a patch, we'd likely take it. (To be clear, I doubt > any of the principal current hackers are interested in doing this.) > > Now, this would still only get you to a lower-bound date somewhere > around 300000 BC. If you need to deal with geological or astronomical > time spans, then yeah you need a new type --- but presumably you would > not feel a need to tie it to Gregorian calendar dates, so the need to > reimplement a ton of related logic would not be there. > > regards, tom lane > > > --000000000000c8d5940624a68133 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi Nina Richards,

Instead of using PostgreSQL'= ;s DATE or TIMESTAMP types, you can store years as NUMERIC or BIGINT values= .
You can manually represent dates before 4713 BC and build custom funct= ions for date operations like addition, subtraction, or comparison.

=

To facilitate comparisons or operations on your custom dates (BC/AD), yo= u can create user-defined functions in PostgreSQL for adding, subtracting, = or comparing dates.

Best Regards,

Asad Ali



On= Thu, Oct 17, 2024 at 5:36=E2=80=AFAM Tom Lane <tgl@sss.pgh.pa.us> wrote:
David Rowley <dgrowleyml@gmail.com> writes:
> It's by no means a trivial thing to do, but it is possible to
> implement new types in PostgreSQL [1]. If you invented your own type,<= br> > you could significantly widen the upper and lower bounds when compared=
> with the standard date type.

However, you'd then have to reimplement some large fraction of the
existing datetime support to have something useful.

We're already inventing freely to use the Gregorian calendar for
millenia before Pope Gregory lived, so I see no conceptual argument
not to extend that back even further.

IIRC the stumbling block for not going back past Julian day 0 was
uncertainty about whether the date2j and j2date algorithms behave
correctly for negative Julian dates --- which at the time was
compounded by the fact that C90 was vague about the rounding direction
for integer division with negative inputs.=C2=A0 Now that we assume C99
with its well-defined rule for that, at least some of the uncertainty
is gone.=C2=A0 Somebody would still have to study that code and either
prove that it's OK or correct it.=C2=A0 And then there would be a
nontrivial amount of effort to work outwards and fix anything else
that is assuming that limitation.=C2=A0 So it would take somebody with
considerable motivation to make it happen, but if such a somebody were
to appear with a patch, we'd likely take it.=C2=A0 (To be clear, I doub= t
any of the principal current hackers are interested in doing this.)

Now, this would still only get you to a lower-bound date somewhere
around 300000 BC.=C2=A0 If you need to deal with geological or astronomical=
time spans, then yeah you need a new type --- but presumably you would
not feel a need to tie it to Gregorian calendar dates, so the need to
reimplement a ton of related logic would not be there.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane


--000000000000c8d5940624a68133--