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.96) (envelope-from ) id 1vR0Sv-0045gf-19 for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 03:57:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vR0St-000Jrs-0e for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 03:57:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vR0Ss-000Jrj-2g for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 03:57:11 +0000 Received: from mail-ua1-x92a.google.com ([2607:f8b0:4864:20::92a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vR0Sq-0032Or-20 for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 03:57:10 +0000 Received: by mail-ua1-x92a.google.com with SMTP id a1e0cc1a2514c-9372149216bso309786241.3 for ; Wed, 03 Dec 2025 19:57:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764820628; x=1765425428; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=KVY7B10z9JHQFOrBU4fT3TUC1UGeoNOdqVUSgptjGro=; b=kogQQWSYkkqzHeuHYCkfwqxyr9rTeyUw1IF8OVBYAjvOMbCxG5AXCv+Iw2gvoTC1KQ vWBaZozzjiiM2z956a/AM/+xFQdd/cc4nODp2tFEKKf8+9PtmHWb76s6B3jmtnvq5aAO V9IAa78NjfZUsUbidTYRrBeFEwqYEu4PSmFQBEj6HM/D5CZwlRsHim2e5xrCfhh+ewxu VEi4poZnwIQC7R6OiK8K8e/4m889ZpPXfUfotyXvCM2/gGkcQ7JiFnU5vSLzd8/dBWKL FRZeJK9c3e6xvWyRqZjOUwwf7YBpQyZhqx1YuGBnA708jxcSwVIQ0+Xsworms20r1d9D mYwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764820628; x=1765425428; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=KVY7B10z9JHQFOrBU4fT3TUC1UGeoNOdqVUSgptjGro=; b=YzTMQNesRXfrkP5R8mUEG3x4lmDAY06AqRTcXlWb8QYr3Er9my4fwIPw1710r7YY4F o/oir9shyikUGGHTYVFiI62y4UStGhAZJ1j1B8SqEmI/73yXVoi4yUCEoZiO3QI11RW4 wtRKZw78/mqc+WR4iDuUr51LQwMAyfDJt/57dq9nw1mngHPJkaPQCypctL0eT0L3AbEl tlnsuzr9H7Y9L8h2vdY6+Dt6hW/PHlRYKpEcqUlT9TxyqawJEKitRRDZY8KdZkaPRBpd R79nTM1g1ntXLEYcQOKWcUjEqBlSx4f4hGcuw/mhB28G1yZVN8xaP3D5VCFbLstdEcci 1Hnw== X-Forwarded-Encrypted: i=1; AJvYcCVpMmVShU0xxd2jXYFOrWiq/EOntZRG6oWJBZwBu5/aM5qAiLd+I+sFtBg5LZr8tNLzsZQ3eXBbC66Q43Xa@lists.postgresql.org X-Gm-Message-State: AOJu0YzwtqfViSgUJG7KnlEv0Bjmj3mbaTxTHESHndTgD8TENYvbq0eh uKKxXBk/Smcby0SClASI1VF1I7+AsrdCpLUSI8YPcVMrOi2sCCNoerWlpVNFKJ2ZpRnrf4z3rcl FPhf057qNfDd9pSG9TLZWJr5ri0j7pMY= X-Gm-Gg: ASbGncs/ytNzzT70nbTsg9q8z6lLzAd2jqc5p8mQ+C6aBBDbGRAJUAMcqqmoJG7jbP2 SV1TI8Vu8b3S4xzYMu/qSWN1QNJVMqY095GMlG7iKl/gTft5JyWCkmbkj5sOpFSRsZypFBG6Rl0 rnszn99YpE1eFAnEs+j7XAp2Tgr3DPGhTJZNuig4t2t75XMBeeJ5ZzKNoP1NLZHfoLRe+oCRrkp zRW3Vp3L0bqcwx2sMyOa8TeTfE94xX299DWtkznYOQrliSklsF7UuTwiZmAFros5iuqzhXJWpqI 2s87DgIFOFTeSGG9VqjjHZAgeKtbUofFfA6S0bNGhOP24A8L4g6ksKJPmxa/7jVC9kkIgXlCCJM 6WtjjLJ79zwBKjFMC0eo27zLPlyNlPaJaScAZ7vSxcZaayvTbVmUodJAJcIUju7IkI62RLofxkj 8nH1wLx7wv X-Google-Smtp-Source: AGHT+IEAjMsaXuAdZKMMj8tdxVoPEAlOtGA/+0eB5UJqrrlfDWkLBe2ZMLVBq0TbrpaoTwXyZimN/SSaqmt27k7KQn8= X-Received: by 2002:a05:6102:b12:b0:5df:c4ec:661e with SMTP id ada2fe7eead31-5e50956030emr578089137.43.1764820628449; Wed, 03 Dec 2025 19:57:08 -0800 (PST) MIME-Version: 1.0 References: <202510210803.3b3vfvygxtjl@alvherre.pgsql> <87530674-E6B6-4C97-A704-78C7E07CF01F@gmail.com> <3DC56A6A-9525-4C05-B45A-9A135A66BC34@justatheory.com> In-Reply-To: From: jian he Date: Thu, 4 Dec 2025 11:56:31 +0800 X-Gm-Features: AWmQ_bmfehirQOOlzuKV1q73aZtw1QPGR8PqZ0kmdX1HCx75f8eqPgzzADTVV6w Message-ID: Subject: Re: PATCH: jsonpath string methods: lower, upper, initcap, l/r/btrim, replace, split_part To: "David E. Wheeler" Cc: Chao Li , =?UTF-8?Q?=C3=81lvaro_Herrera?= , Florents Tselai , Tom Lane , Peter Eisentraut , Robert Haas , Alexander Korotkov , pgsql-hackers , Andrew Dunstan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Dec 1, 2025 at 5:16=E2=80=AFAM David E. Wheeler wrote: > > On Nov 28, 2025, at 05:29, jian he wrote: > > > some "switch" in the attached patch does not preserve the JsonPathItemT= ype order > > consistency, like executeItemOptUnwrapTarget. > > Well-spotted, thank you! Fixed in v15, attached. > hi. seems no deparse regress tests, like: create view vj as select jsonb_path_query('" hello "', '$.ltrim(" ")') = as a; \sv vj that mean the changes in printJsonPathItem are not tested? + /* Create the appropriate jb value to return */ + switch (jsp->type) + { + /* Cases for functions that return text */ + case jpiStrReplace: comments indentation should align with the word "case"? executeStringInternalMethod: + tmp =3D pnstrdup(jb->val.string.val, jb->val.string.len); + str =3D CStringGetTextDatum(tmp); + + /* Internal string functions that accept no arguments */ + switch (jsp->type) + { + case jpiStrReplace: + { + char *from_str, + *to_str; + int from_len, + to_len; + + jspGetLeftArg(jsp, &elem); + if (elem.type !=3D jpiString) + elog(ERROR, "invalid jsonpath item type for .replace() from"); + + from_str =3D jspGetString(&elem, &from_len); + + jspGetRightArg(jsp, &elem); + if (elem.type !=3D jpiString) + elog(ERROR, "invalid jsonpath item type for .replace() to"); + + to_str =3D jspGetString(&elem, &to_len); + + resStr =3D TextDatumGetCString(DirectFunctionCall3Coll(replace_text, + DEFAULT_COLLATION_OID, + CStringGetTextDatum(tmp), + CStringGetTextDatum(from_str), + CStringGetTextDatum(to_str))); + pnstrdup, CStringGetTextDatum copied twice for the same contend? I think you can just `` text *tmp =3D cstring_to_text_with_len(jb->val.string.val, jb->val.string.l= en); Datum str =3D PointerGetDatum(tmp) `` In the first main switch block, there's no need to call ``CStringGetTextDatum(tmp)`` because str is already a Datum. We can simply use str directly. I noticed that almost all of them use DEFAULT_COLLATION_OID, but jpiStrSplitPart uses C_COLLATION_OID. -- jian https://www.enterprisedb.com