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 1soQB9-00B9M4-B4 for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Sep 2024 16:26:52 +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 1soQB7-003gvB-Vb for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Sep 2024 16:26:49 +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 1soQB7-003gv2-L1 for pgsql-hackers@lists.postgresql.org; Wed, 11 Sep 2024 16:26:49 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1soQB3-000g05-Ue for pgsql-hackers@lists.postgresql.org; Wed, 11 Sep 2024 16:26:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 48BGQgnY3835868; Wed, 11 Sep 2024 12:26:42 -0400 From: Tom Lane To: "David E. Wheeler" cc: Andrew Dunstan , Peter Eisentraut , jian he , PostgreSQL Hackers Subject: Re: Document DateStyle effect on jsonpath string() In-reply-to: <3832087.1726070787@sss.pgh.pa.us> References: <56955B33-6959-4FDA-A459-F00363ECDFEE@justatheory.com> <4D874C72-8939-4083-8336-AB114D9E29AD@justatheory.com> <3541398.1725994308@sss.pgh.pa.us> <3654686.1725999372@sss.pgh.pa.us> <5e8879d0-a3c8-4be2-950f-d83aa2af953a@eisentraut.org> <3811774.1726063865@sss.pgh.pa.us> <3824427.1726067484@sss.pgh.pa.us> <5801E26B-E2AB-4BA3-8B69-EF8837389284@justatheory.com> <3832087.1726070787@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 11 Sep 2024 12:06:27 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <3835809.1726071969.0@sss.pgh.pa.us> Date: Wed, 11 Sep 2024 12:26:42 -0400 Message-ID: <3835867.1726072002@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3835809.1726071969.1@sss.pgh.pa.us> I wrote: > I think I'd be content to have string() duplicate that behavior > --- in fact, it seems like it'd be odd if it doesn't match. Building on that thought, maybe we could fix it as attached? This changes the just-committed test cases of course, and I did not look at whether there are documentation changes to make. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="fix-jsonpath-string-output-wip.patch"; charset="us-ascii" Content-ID: <3835809.1726071969.2@sss.pgh.pa.us> Content-Description: fix-jsonpath-string-output-wip.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/utils/adt/jsonpath_exec.c b/src/backend/utils/adt= /jsonpath_exec.c index e3ee0093d4..b9c2443b65 100644 --- a/src/backend/utils/adt/jsonpath_exec.c +++ b/src/backend/utils/adt/jsonpath_exec.c @@ -72,6 +72,7 @@ #include "utils/datetime.h" #include "utils/float.h" #include "utils/formatting.h" +#include "utils/json.h" #include "utils/jsonpath.h" #include "utils/lsyscache.h" #include "utils/memutils.h" @@ -1629,32 +1630,13 @@ executeItemOptUnwrapTarget(JsonPathExecContext *cx= t, JsonPathItem *jsp, break; case jbvDatetime: { - switch (jb->val.datetime.typid) - { - case DATEOID: - tmp =3D DatumGetCString(DirectFunctionCall1(date_out, - jb->val.datetime.value)); - break; - case TIMEOID: - tmp =3D DatumGetCString(DirectFunctionCall1(time_out, - jb->val.datetime.value)); - break; - case TIMETZOID: - tmp =3D DatumGetCString(DirectFunctionCall1(timetz_out, - jb->val.datetime.value)); - break; - case TIMESTAMPOID: - tmp =3D DatumGetCString(DirectFunctionCall1(timestamp_out, - jb->val.datetime.value)); - break; - case TIMESTAMPTZOID: - tmp =3D DatumGetCString(DirectFunctionCall1(timestamptz_out, - jb->val.datetime.value)); - break; - default: - elog(ERROR, "unrecognized SQL/JSON datetime type oid: %u", - jb->val.datetime.typid); - } + char buf[MAXDATELEN + 1]; + + JsonEncodeDateTime(buf, + jb->val.datetime.value, + jb->val.datetime.typid, + &jb->val.datetime.tz); + tmp =3D pstrdup(buf); } break; case jbvNull: ------- =_aaaaaaaaaa0--