From 8fa04ed1fecb48ca8254d2ed7e60a9013fa130a3 Mon Sep 17 00:00:00 2001 From: jian he Date: Wed, 10 Jan 2024 17:46:18 +0800 Subject: [PATCH v3 1/1] add function argument names to regex.* functions. Specifically add function argument names to the following funtions: regexp_replace, regexp_match, regexp_matches regexp_count, regexp_instr, regexp_like, regexp_substr, regexp_split_to_table regexp_split_to_array So it would be easier to understand these functions in psql via \df. Also now these functions can be called in different notaions. --- doc/src/sgml/func.sgml | 50 +++++++++++------------ src/include/catalog/pg_proc.dat | 71 ++++++++++++++++++++++++++------- 2 files changed, 82 insertions(+), 39 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index de78d58d..23ef07a5 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -3299,7 +3299,7 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in regexp_instr ( string text, pattern text [, start integer - [, N integer + [, occurrence integer [, endoption integer [, flags text [, subexpr integer ] ] ] ] ] ) @@ -3307,7 +3307,7 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in Returns the position within string where - the N'th match of the POSIX regular + the occurrence'th match of the POSIX regular expression pattern occurs, or zero if there is no such match; see . @@ -3413,14 +3413,14 @@ 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 + occurrence integer [, flags text ] ) text - Replaces the substring that is the N'th + Replaces the substring that is the occurrence'th match to the POSIX regular expression pattern, - or all such matches if N is zero; see + or all such matches if occurrence is zero; see . @@ -3478,14 +3478,14 @@ SELECT NOT(ROW(table.*) IS NOT NULL) FROM TABLE; -- detect at least one null in regexp_substr ( string text, pattern text [, start integer - [, N integer + [, occurrence integer [, flags text [, subexpr integer ] ] ] ] ) text Returns the substring within string that - matches the N'th occurrence of the POSIX + matches the occurrence'th occurrence of the POSIX regular expression pattern, or NULL if there is no such match; see . @@ -5888,13 +5888,13 @@ regexp_count('ABCABCAXYaxy', 'A.', 1, 'i') 4 The regexp_instr function returns the starting or - ending position of the N'th match of a + ending position of the occurrence'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 + , occurrence , endoption , flags , subexpr @@ -5903,8 +5903,8 @@ regexp_count('ABCABCAXYaxy', 'A.', 1, 'i') 4 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 + If occurrence is specified + then the occurrence'th match of the pattern is located, otherwise the first match is located. If the endoption parameter is omitted or specified as zero, the function returns the position of the first @@ -6024,8 +6024,8 @@ SELECT (regexp_match('foobarbequebaz', 'bar.*que'))[1]; expression pattern to a string. It has the same syntax as regexp_match. This function returns no rows if there is no match, one row if there is - a match and the g flag is not given, or N - rows if there are N matches and the g flag + a match and the g flag is not given, or occurrence + rows if there are occurrence matches and the g flag is given. Each returned row is a text array containing the whole matched substring or the substrings matching parenthesized subexpressions of the pattern, just as described above @@ -6076,18 +6076,18 @@ 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 + , occurrence , flags ). - (Notice that N cannot be specified + (Notice that occurrence cannot be specified unless start is, but flags can be given in any case.) - The source string is returned unchanged if + The 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 @@ -6102,14 +6102,14 @@ SELECT col1, (SELECT regexp_matches(col2, '(bar)(beque)')) FROM tab; the string, but if the start parameter is provided then beginning from that character index. By default, only the first match of the pattern is replaced. - If N is specified and is greater than zero, - then the N'th match of the pattern + If occurrence is specified and is greater than zero, + then the occurrence'th match of the pattern is replaced. If the g flag is given, or - if N is specified and is zero, then all + if occurrence is specified and is zero, then all matches at or after the start position are replaced. (The g flag is ignored - when N is specified.) + when occurrence is specified.) The flags parameter is an optional text string containing zero or more single-letter flags that change the function's behavior. Supported flags (though @@ -6220,7 +6220,7 @@ SELECT foo FROM regexp_split_to_table('the quick brown fox', '\s*') AS foo; regexp_substr(string, pattern , start - , N + , occurrence , flags , subexpr ). @@ -6228,8 +6228,8 @@ SELECT foo FROM regexp_split_to_table('the quick brown fox', '\s*') AS foo; 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 + If occurrence is specified + then the occurrence'th match of the pattern is returned, otherwise the first match is returned. The flags parameter is an optional text string containing zero or more single-letter flags that change the diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 79793927..3b4330a6 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -3611,105 +3611,148 @@ prosrc => 'replace_text' }, { oid => '2284', descr => 'replace text using regexp', proname => 'regexp_replace', prorettype => 'text', - proargtypes => 'text text text', prosrc => 'textregexreplace_noopt' }, + proargtypes => 'text text text', + proargnames => '{string, pattern, replacement}', + prosrc => 'textregexreplace_noopt' }, { oid => '2285', descr => 'replace text using regexp', proname => 'regexp_replace', prorettype => 'text', - proargtypes => 'text text text text', prosrc => 'textregexreplace' }, + proargtypes => 'text text text text', + proargnames => '{string, pattern, replacement, flags}', + prosrc => 'textregexreplace' }, { oid => '6251', descr => 'replace text using regexp', proname => 'regexp_replace', prorettype => 'text', proargtypes => 'text text text int4 int4 text', + proargnames => '{string, pattern, replacement, start, occurrence, flags}', prosrc => 'textregexreplace_extended' }, { oid => '6252', descr => 'replace text using regexp', proname => 'regexp_replace', prorettype => 'text', proargtypes => 'text text text int4 int4', + proargnames => '{string, pattern, replacement, start, occurrence}', prosrc => 'textregexreplace_extended_no_flags' }, { oid => '6253', descr => 'replace text using regexp', proname => 'regexp_replace', prorettype => 'text', proargtypes => 'text text text int4', + proargnames => '{string, pattern, replacement, start}', prosrc => 'textregexreplace_extended_no_n' }, { oid => '3396', descr => 'find first match for regexp', proname => 'regexp_match', prorettype => '_text', proargtypes => 'text text', + proargnames => '{string, pattern}', prosrc => 'regexp_match_no_flags' }, { oid => '3397', descr => 'find first match for regexp', proname => 'regexp_match', prorettype => '_text', - proargtypes => 'text text text', prosrc => 'regexp_match' }, + proargtypes => 'text text text', + proargnames => '{string, pattern, flags}', + prosrc => 'regexp_match' }, { oid => '2763', descr => 'find match(es) for regexp', proname => 'regexp_matches', prorows => '1', proretset => 't', prorettype => '_text', proargtypes => 'text text', + proargnames => '{string, pattern}', prosrc => 'regexp_matches_no_flags' }, { oid => '2764', descr => 'find match(es) for regexp', proname => 'regexp_matches', prorows => '10', proretset => 't', prorettype => '_text', proargtypes => 'text text text', + proargnames => '{string, pattern, flags}', prosrc => 'regexp_matches' }, { oid => '6254', descr => 'count regexp matches', proname => 'regexp_count', prorettype => 'int4', proargtypes => 'text text', + proargnames => '{string, pattern}', prosrc => 'regexp_count_no_start' }, { oid => '6255', descr => 'count regexp matches', proname => 'regexp_count', prorettype => 'int4', - proargtypes => 'text text int4', prosrc => 'regexp_count_no_flags' }, + proargtypes => 'text text int4', + proargnames => '{string, pattern, start}', + prosrc => 'regexp_count_no_flags' }, { oid => '6256', descr => 'count regexp matches', proname => 'regexp_count', prorettype => 'int4', - proargtypes => 'text text int4 text', prosrc => 'regexp_count' }, + proargtypes => 'text text int4 text', + proargnames => '{string, pattern, start, flags}', + prosrc => 'regexp_count' }, { oid => '6257', descr => 'position of regexp match', proname => 'regexp_instr', prorettype => 'int4', proargtypes => 'text text', + proargnames => '{string, pattern}', prosrc => 'regexp_instr_no_start' }, { oid => '6258', descr => 'position of regexp match', proname => 'regexp_instr', prorettype => 'int4', - proargtypes => 'text text int4', prosrc => 'regexp_instr_no_n' }, + proargtypes => 'text text int4', + proargnames => '{string, pattern, start}', + prosrc => 'regexp_instr_no_n' }, { oid => '6259', descr => 'position of regexp match', proname => 'regexp_instr', prorettype => 'int4', - proargtypes => 'text text int4 int4', prosrc => 'regexp_instr_no_endoption' }, + proargtypes => 'text text int4 int4', + proargnames => '{string, pattern, start, occurrence}', + prosrc => 'regexp_instr_no_endoption' }, { oid => '6260', descr => 'position of regexp match', proname => 'regexp_instr', prorettype => 'int4', proargtypes => 'text text int4 int4 int4', + proargnames => '{string, pattern, start, occurrence, endoption}', prosrc => 'regexp_instr_no_flags' }, { oid => '6261', descr => 'position of regexp match', proname => 'regexp_instr', prorettype => 'int4', proargtypes => 'text text int4 int4 int4 text', + proargnames => '{string, pattern, start, occurrence, endoption, flags}', prosrc => 'regexp_instr_no_subexpr' }, { oid => '6262', descr => 'position of regexp match', proname => 'regexp_instr', prorettype => 'int4', proargtypes => 'text text int4 int4 int4 text int4', + proargnames => '{string, pattern, start, occurrence, endoption, flags, subexpr}', prosrc => 'regexp_instr' }, { oid => '6263', descr => 'test for regexp match', - proname => 'regexp_like', prorettype => 'bool', proargtypes => 'text text', + proname => 'regexp_like', prorettype => 'bool', + proargtypes => 'text text', + proargnames => '{string, pattern}', prosrc => 'regexp_like_no_flags' }, { oid => '6264', descr => 'test for regexp match', proname => 'regexp_like', prorettype => 'bool', - proargtypes => 'text text text', prosrc => 'regexp_like' }, + proargtypes => 'text text text', + proargnames => '{string, pattern,flags}', + prosrc => 'regexp_like' }, { oid => '6265', descr => 'extract substring that matches regexp', proname => 'regexp_substr', prorettype => 'text', proargtypes => 'text text', + proargnames => '{string, pattern}', prosrc => 'regexp_substr_no_start' }, { oid => '6266', descr => 'extract substring that matches regexp', proname => 'regexp_substr', prorettype => 'text', - proargtypes => 'text text int4', prosrc => 'regexp_substr_no_n' }, + proargtypes => 'text text int4', + proargnames => '{string, pattern, start}', + prosrc => 'regexp_substr_no_n' }, { oid => '6267', descr => 'extract substring that matches regexp', proname => 'regexp_substr', prorettype => 'text', - proargtypes => 'text text int4 int4', prosrc => 'regexp_substr_no_flags' }, + proargtypes => 'text text int4 int4', + proargnames => '{string, pattern, start, occurrence}', + prosrc => 'regexp_substr_no_flags' }, { oid => '6268', descr => 'extract substring that matches regexp', proname => 'regexp_substr', prorettype => 'text', proargtypes => 'text text int4 int4 text', + proargnames => '{string, pattern, start, occurrence, flags}', prosrc => 'regexp_substr_no_subexpr' }, { oid => '6269', descr => 'extract substring that matches regexp', proname => 'regexp_substr', prorettype => 'text', - proargtypes => 'text text int4 int4 text int4', prosrc => 'regexp_substr' }, + proargtypes => 'text text int4 int4 text int4', + proargnames => '{string, pattern, start, occurrence, flags, subexpr}', + prosrc => 'regexp_substr' }, { oid => '2088', descr => 'split string by field_sep and return field_num', proname => 'split_part', prorettype => 'text', proargtypes => 'text text int4', prosrc => 'split_part' }, { oid => '2765', descr => 'split string by pattern', proname => 'regexp_split_to_table', prorows => '1000', proretset => 't', prorettype => 'text', proargtypes => 'text text', + proargnames => '{string, pattern}', prosrc => 'regexp_split_to_table_no_flags' }, { oid => '2766', descr => 'split string by pattern', proname => 'regexp_split_to_table', prorows => '1000', proretset => 't', prorettype => 'text', proargtypes => 'text text text', + proargnames => '{string, pattern, flags}', prosrc => 'regexp_split_to_table' }, { oid => '2767', descr => 'split string by pattern', proname => 'regexp_split_to_array', prorettype => '_text', - proargtypes => 'text text', prosrc => 'regexp_split_to_array_no_flags' }, + proargtypes => 'text text', + proargnames => '{string, pattern}', + prosrc => 'regexp_split_to_array_no_flags' }, { oid => '2768', descr => 'split string by pattern', proname => 'regexp_split_to_array', prorettype => '_text', - proargtypes => 'text text text', prosrc => 'regexp_split_to_array' }, + proargtypes => 'text text text', + proargnames => '{string, pattern, flags}', + prosrc => 'regexp_split_to_array' }, { oid => '9030', descr => 'convert int4 number to binary', proname => 'to_bin', prorettype => 'text', proargtypes => 'int4', prosrc => 'to_bin32' }, -- 2.34.1