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 1su8Dh-004QmR-VQ for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Sep 2024 10:29:06 +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 1su8Dg-006wZz-Ch for pgsql-hackers@arkaria.postgresql.org; Fri, 27 Sep 2024 10:29:04 +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 1su8Dg-006wZp-1Z for pgsql-hackers@lists.postgresql.org; Fri, 27 Sep 2024 10:29:04 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1su8DW-001LGR-JR for pgsql-hackers@lists.postgresql.org; Fri, 27 Sep 2024 10:29:01 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-42cb5b3c57eso18149215e9.2 for ; Fri, 27 Sep 2024 03:28:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727432935; x=1728037735; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4qgRyDSI6zYik6GM6+mYAwBHqm+YS30nLfhf/U2ALDg=; b=DOQs7RLLlBsXWGmFvn66OVM4Yk64e7Pxo3PB67bKe42jVCXYYmV8JUqtO194AiatRA 1HHPIFUEuyvaRKL9eEznmtyVESpz2GZ5IxYd4VACvhFAvlexrpeKX7ljNgjemAyyKVnI OIJ2EItRXaK4jOdMdlRODnH84EReuxZB38ysWQEI4vL2SSA2Ngmif3zucU3sZ+oWh6dt UQvG0jASCtILN+1TtxuMLv+WRDmFfumO8F0sGnb6bV+HrWkRTxlvhrSVAcywbBhKMCpU ULrezdZm6tPbaSKmyNKJ6+LLzftdnGK7Ig7HS2IPABOzZHFSs0L1QQ54+mrzEiJNAUeb m+Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727432935; x=1728037735; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4qgRyDSI6zYik6GM6+mYAwBHqm+YS30nLfhf/U2ALDg=; b=PoYeqc5TpcYYTnN8GV8D7pYmuxUXRLhpoI1jNR3d+eOMC5vb4yWiWQeVg8O7BoevvZ Zt2RhqsDpVt0BYEXw/Ttmit/bZnI901GiBvvHcdekNrlDk1FwvQkTkPf0b3z5sfr4NsN 4LjsFTzLcIZ/K2G+nYyhbg5yhteUz7fmHO6mtephl2ksuSDNjopT2MxGMUIKkeZzAmbe IrB5OWjf6jlsxAiM5OJkm3CtYDFfsTZNKk7FSfrwSUSmR/yurlYxhAwncuyfnWNP6gsG UbVO1viNFiDpBEVYJA3owx5x/LUvxTaaLjWrr+6eyvRTQ/pNrhzoLbfakxckyyxZhAoN qpsQ== X-Forwarded-Encrypted: i=1; AJvYcCUbJWu37FH70hCNkuob+UOgffMswCrLgv6XAIIagv2gWO48j+PRIn6jTCukSqEm+gU9YOP/W1R6krxfKdrG@lists.postgresql.org X-Gm-Message-State: AOJu0Yxe9tFiLGGJcMdlnh1R1QOVIcdwy5dZIGW9YQ8ISuXtJOITkDrJ 0FcWXN6sPLYAk4RY5YgVlu1uLvVoOHUpUA6bygcIbPBNVFdF+rGi X-Google-Smtp-Source: AGHT+IEYwAVmY5Ta+e8PqYXR5V9wadENquQZ98nuTJ1B1qdv4fbeP31hsyvHcucXcQ61inA+ztcxvA== X-Received: by 2002:a05:600c:4e08:b0:42c:bad0:6c1c with SMTP id 5b1f17b1804b1-42f5844b3b4mr20663105e9.18.1727432934402; Fri, 27 Sep 2024 03:28:54 -0700 (PDT) Received: from smtpclient.apple (adsl-192.176.58.225.tellas.gr. [176.58.225.192]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e96a56fddsm69771655e9.46.2024.09.27.03.28.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Sep 2024 03:28:53 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3818.100.11.1.3\)) Subject: Re: PATCH: jsonpath string methods: lower, upper, initcap, l/r/btrim, replace, split_part From: Florents Tselai In-Reply-To: <73C52BC6-E708-43CF-A79B-AB22AEDEC8A7@justatheory.com> Date: Fri, 27 Sep 2024 13:28:21 +0300 Cc: Alexander Korotkov , Tom Lane , pgsql-hackers Content-Transfer-Encoding: quoted-printable Message-Id: References: <145894.1727298237@sss.pgh.pa.us> <73C52BC6-E708-43CF-A79B-AB22AEDEC8A7@justatheory.com> To: "David E. Wheeler" X-Mailer: Apple Mail (2.3818.100.11.1.3) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 27 Sep 2024, at 12:45=E2=80=AFPM, David E. Wheeler = wrote: >=20 > On Sep 26, 2024, at 13:59, Florents Tselai = wrote: >=20 >> Speaking of extensible: the jsonpath standard does mention function = extensions [1] , >> so it looks like we're covered by the standard, and the mutability = aspect is an implementation detail. No? >=20 > That=E2=80=99s not the standard used for Postgres jsonpath. Postgres = follows the SQL/JSON standard in the SQL standard, which is not publicly = available, but a few people on the list have copies they=E2=80=99ve = purchased and so could provide some context. >=20 > In a previous post I wondered if the SQL standard had some facility = for function extensions, but I suspect not. Maybe in the next iteration? >=20 >> And having said that, the whole jsonb/jsonpath parser/executor = infrastructure is extremely powerful >> and kinda under-utilized if we use it "only" for jsonpath. >> Tbh, I can see it supporting more specific DSLs and even offering = hooks for extensions. >> And I know for certain I'm not the only one thinking about this. >> See [2] for example where they've lifted, shifted and renamed the = jsonb/jsonpath infra to build a separate language for graphs >=20 > I=E2=80=99m all for extensibility, though jsonpath does need to = continue to comply with the SQL standard. Do you have some idea of the = sorts of hooks that would allow extension authors to use some of that = underlying capability? Re-tracing what I had to do 1. Define a new JsonPathItemType jpiMyExtType and map it to a = JsonPathKeyword 2. Add a new JsonPathKeyword and make the lexer and parser aware of = that, 3. Tell the main executor executeItemOptUnwrapTarget what to do when the = new type is matched. I think 1, 2 are the trickiest because they require hooks to = jsonpath_scan.l and parser jsonpath_gram.y=20 3. is the meat of a potential hook, which would be something like=20 extern JsonPathExecResult executeOnMyJsonpathItem(JsonPathExecContext = *cxt, JsonbValue *jb, JsonValueList *found); This should be called by the main executor executeItemOptUnwrapTarget = when it encounters case jpiMyExtType It looks like quite an endeavor, to be honest.=