From 372a0c6cb894194b819fc380efda179bf6d1055d Mon Sep 17 00:00:00 2001 From: jian he Date: Thu, 4 Apr 2024 21:50:13 +0800 Subject: [PATCH v4 1/1] add regex functions argument names. 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. now these functions can be called in different notaions. discussion: https://postgr.es/m/CACJufxG3NFKKsh6x4fRLv8h3V-HvN4W5dA%3DzNKMxsNcDwOKang%40mail.gmail.com --- 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 ff690113..57ad1624 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -3332,7 +3332,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 + [, count integer [, endoption integer [, flags text [, subexpr integer ] ] ] ] ] ) @@ -3340,7 +3340,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 count'th match of the POSIX regular expression pattern occurs, or zero if there is no such match; see . @@ -3446,14 +3446,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 + count integer [, flags text ] ) text - Replaces the substring that is the N'th + Replaces the substring that is the count'th match to the POSIX regular expression pattern, - or all such matches if N is zero; see + or all such matches if count is zero; see . @@ -3511,14 +3511,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 + [, count integer [, flags text [, subexpr integer ] ] ] ] ) text Returns the substring within string that - matches the N'th occurrence of the POSIX + matches the count'th occurrence of the POSIX regular expression pattern, or NULL if there is no such match; see . @@ -5921,13 +5921,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 count'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 + , count , endoption , flags , subexpr @@ -5936,8 +5936,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 count is specified + then the count'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 @@ -6057,8 +6057,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 count + rows if there are count 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 @@ -6109,18 +6109,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 + , count , flags ). - (Notice that N cannot be specified + (Notice that count 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 @@ -6135,14 +6135,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 count is specified and is greater than zero, + then the count'th match of the pattern is replaced. If the g flag is given, or - if N is specified and is zero, then all + if count 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 count 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 @@ -6253,7 +6253,7 @@ SELECT foo FROM regexp_split_to_table('the quick brown fox', '\s*') AS foo; regexp_substr(string, pattern , start - , N + , count , flags , subexpr ). @@ -6261,8 +6261,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 count is specified + then the count'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 153d816a..be28950c 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -3623,105 +3623,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, count, 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, count}', 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, count}', + 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, count, 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, count, 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, count, 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, count}', + 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, count, 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, count, 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' }, base-commit: 6f4d63e989ffbdb44f5856a17fae5ae68c40327d -- 2.34.1