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 1rKMfp-002GWl-W3 for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Jan 2024 18:06:03 +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 1rKMfm-00D0Od-8J for pgsql-hackers@arkaria.postgresql.org; Mon, 01 Jan 2024 18:05:58 +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.94.2) (envelope-from ) id 1rKMfl-00D0OU-KN for pgsql-hackers@lists.postgresql.org; Mon, 01 Jan 2024 18:05:57 +0000 Received: from out-176.mta0.migadu.com ([2001:41d0:1004:224b::b0]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rKMfh-00DFIA-Li for pgsql-hackers@lists.postgresql.org; Mon, 01 Jan 2024 18:05:55 +0000 Mime-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nmfay.com; s=key1; t=1704132349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z+e9wXciHj20kl8ZJ2R6jU2O1Zj/cfEPDXjiCW4NVi4=; b=QYhTTAnfx9N3dzB25X4uievNm0zf5n9fCC5jKaCXISGpiooiuyd1HNoK/c+KeOuInXvnlL L6U9DuUP7BH3CR5V2HiBxV/1XjIKObCOfMHIFHs6d9sMEbohht8YoKE77ztWrMc3nNvNZJ 8BM0l4l5Z4zAUe9FQmdagW5mFL1hGCGtf+uruesjhM8HrvnICNe+N2QCiV1QuQ1OjvlEzD 0+M5Tl2w3H4zPPkcoDgCj1phTsEu0/ehwl6EzSWleFcB67xV136VZ02HNSpSZ1XFjxqRU8 wDC06bDgHGyc6ea1jTmP4NtzmD0Nbw7c6KNaJwXhgwmQVq/PJdXFU9q6Xg4LYg== Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Mon, 01 Jan 2024 13:05:45 -0500 Message-Id: To: "jian he" , "Peter Eisentraut" Cc: "PostgreSQL Hackers" Subject: Re: add function argument names to regex* functions. X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: "Dian Fay" References: In-Reply-To: X-Migadu-Flow: FLOW_OUT List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed Dec 27, 2023 at 10:28 PM EST, jian he wrote: > On Thu, Dec 28, 2023 at 6:25=E2=80=AFAM Peter Eisentraut wrote: > > > > On 27.12.23 17:53, jian he wrote: > > > similar to [1], add function argument names to the following function= s: > > > regexp_like, regexp_match,regexp_matches,regexp_replace, > > > regexp_substr,regexp_split_to_array,regexp_split_to_table,regexp_coun= t > > > > Note that these functions are a quasi-standard that is shared with othe= r > > SQL implementations. It might be worth looking around if there are > > already other implementations of this idea. > > > > turns out people do like calling functions via explicitly mentioning > function argument names, example: [0] > There are no provisions for the argument names. > > I looked around the oracle implementation in [1], and the oracle regex > related function argumentation name in [2] > I use the doc [3] syntax explanation and add the related function names. > > Current, regex.* function syntax seems fine. but only parameter `N` > seems a little bit weird. > If we change the function's argument name, we also need to change > function syntax explanation in the doc; vise versa. > > QUOTE: > The regexp_instr function returns the starting or ending position of > the N'th match of a POSIX regular expression pattern to a string, or > zero if there is no such match. It has the syntax regexp_instr(string, > pattern [, start [, N [, endoption [, flags [, subexpr ]]]]]). pattern > is searched for in string, normally from the beginning of the string, > but if the start parameter is provided then beginning from that > character index. If N is specified then the N'th match of the pattern > is located, otherwise the first match is located. > END OF QUOTE. > > maybe we can change `N` to occurrence. but `occurrence` is kind of verbos= e. > > [0] https://stackoverflow.com/questions/33387348/oracle-named-parameters-= in-regular-functions > [1] https://docs.oracle.com/en/database/oracle/oracle-database/23/sqlrf/R= EGEXP_SUBSTR.html#GUID-2903904D-455F-4839-A8B2-1731EF4BD099 > [2] https://dbfiddle.uk/h_SBDEKi > [3] https://www.postgresql.org/docs/current/functions-matching.html#FUNCT= IONS-POSIX-REGEXP I've been trying to use named arguments more diligently so expanding support for built-in functions is welcome. The patch applies cleanly and works as advertised. I agree that the parameter name `n` is not ideal. For example, in `regexp_replace` it's easy to misinterpret it as "make up to n replacements". This has not been a problem when `n` only lives in the documentation which explains exactly what it does, but that context is not readily available in code expressing `n =3D> 3`. Another possibility is `index`, which is relatively short and not a reserved keyword ^1. `position` is not as precise but would avoid the conceptual overloading of ordinary indices. 1. https://www.postgresql.org/docs/current/sql-keywords-appendix.html