Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0562820

Browse files
committed
Document regexp_matches() better and show example of single-row usage.
1 parent3b19a45 commit0562820

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.515 2010/06/0302:06:10 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.516 2010/06/0314:40:42 momjian Exp $ -->
22

33
<chapter id="functions">
44
<title>Functions and Operators</title>
@@ -3445,19 +3445,22 @@ regexp_replace('foobarbaz', 'b(..)', E'X\\1Y', 'g')
34453445
</para>
34463446

34473447
<para>
3448-
The <function>regexp_matches</> function returnsall of the captured
3449-
substrings resulting from matching a POSIX regular expression pattern.
3450-
It has the syntax
3448+
The <function>regexp_matches</> function returnsa text array of
3449+
all of the capturedsubstrings resulting from matching a POSIX
3450+
regular expression pattern.It has the syntax
34513451
<function>regexp_matches</function>(<replaceable>string</>, <replaceable>pattern</>
34523452
<optional>, <replaceable>flags</> </optional>).
3453-
If there is no match to the <replaceable>pattern</>, the function returns
3454-
no rows. If there is a match, the function returns a text array whose
3453+
The function can return no rows, one row, or multiple rows (see
3454+
the <literal>g</> flag below). If the <replaceable>pattern</>
3455+
does not match, the function returns no rows. If the pattern
3456+
contains no parenthesized subexpressions, then each row
3457+
returned is a single-element text array containing the substring
3458+
matching the whole pattern. If the pattern contains parenthesized
3459+
subexpressions, the function returns a text array whose
34553460
<replaceable>n</>'th element is the substring matching the
34563461
<replaceable>n</>'th parenthesized subexpression of the pattern
34573462
(not counting <quote>non-capturing</> parentheses; see below for
3458-
details). If the pattern does not contain any parenthesized
3459-
subexpressions, then the result is a single-element text array containing
3460-
the substring matching the whole pattern.
3463+
details).
34613464
The <replaceable>flags</> parameter is an optional text
34623465
string containing zero or more single-letter flags that change the
34633466
function's behavior. Flag <literal>g</> causes the function to find
@@ -3487,6 +3490,16 @@ SELECT regexp_matches('foobarbequebaz', 'barbeque');
34873490
----------------
34883491
{barbeque}
34893492
(1 row)
3493+
</programlisting>
3494+
</para>
3495+
3496+
<para>
3497+
It is possible to force <function>regexp_matches()</> to always
3498+
return one row by using a sub-select; this is particularly useful
3499+
in a <literal>SELECT</> target list when you want all rows
3500+
returned, even non-matching ones:
3501+
<programlisting>
3502+
SELECT col1, (SELECT regexp_matches(col2, '(bar)(beque)')) FROM tab;
34903503
</programlisting>
34913504
</para>
34923505

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp