From 580f8727ca93b7b9a2ce49746b9cdbcb0a2b4a7e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 25 Jul 2024 14:51:46 -0400 Subject: Add argument names to the regexp_XXX functions. This change allows these functions to be called using named-argument notation, which can be helpful for readability, particularly for the ones with many arguments. There was considerable debate about exactly which names to use, but in the end we settled on the names already shown in our documentation table 9.10. The citext extension provides citext-aware versions of some of these functions, so add argument names to those too. In passing, fix table 9.10's syntax synopses for regexp_match, which were slightly wrong about which combinations of arguments are allowed. Jian He, reviewed by Dian Fay and others Discussion: https://postgr.es/m/CACJufxG3NFKKsh6x4fRLv8h3V-HvN4W5dA=zNKMxsNcDwOKang@mail.gmail.com --- doc/src/sgml/func.sgml | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index fd5699f4d85..b669ab7f977 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -3426,7 +3426,6 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in regexp_replace regexp_replace ( string text, pattern text, replacement text - [, start integer ] [, flags text ] ) text @@ -3445,20 +3444,27 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in regexp_replace ( string text, pattern text, replacement text, - start integer, - N integer - [, flags text ] ) + start integer + [, N integer + [, flags text ] ] ) text Replaces the substring that is the N'th match to the POSIX regular expression pattern, - or all such matches if N is zero; see + or all such matches if N is zero, with the + search beginning at the start'th character + of string. If N is + omitted, it defaults to 1. See . regexp_replace('Thomas', '.', 'X', 3, 2) ThoXas + + + regexp_replace(string=>'hello world', pattern=>'l', replacement=>'XX', start=>1, "N"=>2) + helXXo world @@ -5963,7 +5969,7 @@ regexp_count('ABCABCAXYaxy', 'A.', 1, 'i') 4 regexp_instr('number of your street, town zip, FR', '[^,]+', 1, 2) 23 -regexp_instr('ABCDEFGHI', '(c..)(...)', 1, 1, 0, 'i', 2) +regexp_instr(string=>'ABCDEFGHI', pattern=>'(c..)(...)', start=>1, "N"=>1, endoption=>0, flags=>'i', subexpr=>2) 6 @@ -6109,7 +6115,7 @@ SELECT col1, (SELECT regexp_matches(col2, '(bar)(beque)')) FROM tab; The regexp_replace function provides substitution of new text for substrings that match POSIX regular expression patterns. It has the syntax - regexp_replace(source, + regexp_replace(string, pattern, replacement , start , N @@ -6118,9 +6124,9 @@ SELECT col1, (SELECT regexp_matches(col2, '(bar)(beque)')) FROM tab; (Notice that N cannot be specified unless start is, but flags can be given in any case.) - The source string is returned unchanged if + The source string is returned unchanged if there is no match to the pattern. If there is a - match, the source string is returned with the + match, the string is returned with the replacement string substituted for the matching substring. The replacement string can contain \n, where n is 1 @@ -6161,7 +6167,7 @@ regexp_replace('foobarbaz', 'b(..)', 'X\1Y', 'g') fooXarYXazY regexp_replace('A PostgreSQL function', 'a|e|i|o|u', 'X', 1, 0, 'i') X PXstgrXSQL fXnctXXn -regexp_replace('A PostgreSQL function', 'a|e|i|o|u', 'X', 1, 3, 'i') +regexp_replace(string=>'A PostgreSQL function', pattern=>'a|e|i|o|u', replacement=>'X', start=>1, "N"=>3, flags=>'i') A PostgrXSQL function -- cgit v1.2.3