Skip to content

Commit 66f1630

Browse files
committed
Add string_to_table() function.
This splits a string at occurrences of a delimiter. It is exactly like string_to_array() except for producing a set of values instead of an array of values. Thus, the relationship of these two functions is the same as between regexp_split_to_table() and regexp_split_to_array(). Although the same results could be had from unnest(string_to_array()), this is somewhat faster than that, and anyway it seems reasonable to have it for symmetry with the regexp functions. Pavel Stehule, reviewed by Peter Smith Discussion: https://postgr.es/m/CAFj8pRD8HOpjq2TqeTBhSo_QkzjLOhXzGCpKJ4nCs7Y9SQkuPw@mail.gmail.com
1 parent fd5e3b2 commit 66f1630

File tree

6 files changed

+354
-93
lines changed

6 files changed

+354
-93
lines changed

doc/src/sgml/func.sgml

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3220,7 +3220,7 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
32203220
</para>
32213221
<para>
32223222
Splits <parameter>string</parameter> using a POSIX regular
3223-
expression as the delimiter; see
3223+
expression as the delimiter, producing an array of results; see
32243224
<xref linkend="functions-posix-regexp"/>.
32253225
</para>
32263226
<para>
@@ -3239,7 +3239,7 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
32393239
</para>
32403240
<para>
32413241
Splits <parameter>string</parameter> using a POSIX regular
3242-
expression as the delimiter; see
3242+
expression as the delimiter, producing a set of results; see
32433243
<xref linkend="functions-posix-regexp"/>.
32443244
</para>
32453245
<para>
@@ -3460,6 +3460,65 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
34603460
</para></entry>
34613461
</row>
34623462

3463+
<row>
3464+
<entry role="func_table_entry"><para role="func_signature">
3465+
<indexterm>
3466+
<primary>string_to_array</primary>
3467+
</indexterm>
3468+
<function>string_to_array</function> ( <parameter>string</parameter> <type>text</type>, <parameter>delimiter</parameter> <type>text</type> <optional>, <parameter>null_string</parameter> <type>text</type> </optional> )
3469+
<returnvalue>text[]</returnvalue>
3470+
</para>
3471+
<para>
3472+
Splits the <parameter>string</parameter> at occurrences
3473+
of <parameter>delimiter</parameter> and forms the resulting fields
3474+
into a <type>text</type> array.
3475+
If <parameter>delimiter</parameter> is <literal>NULL</literal>,
3476+
each character in the <parameter>string</parameter> will become a
3477+
separate element in the array.
3478+
If <parameter>delimiter</parameter> is an empty string, then
3479+
the <parameter>string</parameter> is treated as a single field.
3480+
If <parameter>null_string</parameter> is supplied and is
3481+
not <literal>NULL</literal>, fields matching that string are
3482+
replaced by <literal>NULL</literal>.
3483+
</para>
3484+
<para>
3485+
<literal>string_to_array('xx~~yy~~zz', '~~', 'yy')</literal>
3486+
<returnvalue>{xx,NULL,zz}</returnvalue>
3487+
</para></entry>
3488+
</row>
3489+
3490+
<row>
3491+
<entry role="func_table_entry"><para role="func_signature">
3492+
<indexterm>
3493+
<primary>string_to_table</primary>
3494+
</indexterm>
3495+
<function>string_to_table</function> ( <parameter>string</parameter> <type>text</type>, <parameter>delimiter</parameter> <type>text</type> <optional>, <parameter>null_string</parameter> <type>text</type> </optional> )
3496+
<returnvalue>setof text</returnvalue>
3497+
</para>
3498+
<para>
3499+
Splits the <parameter>string</parameter> at occurrences
3500+
of <parameter>delimiter</parameter> and returns the resulting fields
3501+
as a set of <type>text</type> rows.
3502+
If <parameter>delimiter</parameter> is <literal>NULL</literal>,
3503+
each character in the <parameter>string</parameter> will become a
3504+
separate row of the result.
3505+
If <parameter>delimiter</parameter> is an empty string, then
3506+
the <parameter>string</parameter> is treated as a single field.
3507+
If <parameter>null_string</parameter> is supplied and is
3508+
not <literal>NULL</literal>, fields matching that string are
3509+
replaced by <literal>NULL</literal>.
3510+
</para>
3511+
<para>
3512+
<literal>string_to_table('xx~^~yy~^~zz', '~^~', 'yy')</literal>
3513+
<returnvalue></returnvalue>
3514+
<programlisting>
3515+
xx
3516+
NULL
3517+
zz
3518+
</programlisting>
3519+
</para></entry>
3520+
</row>
3521+
34633522
<row>
34643523
<entry role="func_table_entry"><para role="func_signature">
34653524
<indexterm>
@@ -17819,33 +17878,6 @@ SELECT NULLIF(value, '(none)') ...
1781917878
</para></entry>
1782017879
</row>
1782117880

17822-
<row>
17823-
<entry role="func_table_entry"><para role="func_signature">
17824-
<indexterm>
17825-
<primary>string_to_array</primary>
17826-
</indexterm>
17827-
<function>string_to_array</function> ( <parameter>string</parameter> <type>text</type>, <parameter>delimiter</parameter> <type>text</type> <optional>, <parameter>null_string</parameter> <type>text</type> </optional> )
17828-
<returnvalue>text[]</returnvalue>
17829-
</para>
17830-
<para>
17831-
Splits the <parameter>string</parameter> at occurrences
17832-
of <parameter>delimiter</parameter> and forms the remaining data
17833-
into a <type>text</type> array.
17834-
If <parameter>delimiter</parameter> is <literal>NULL</literal>,
17835-
each character in the <parameter>string</parameter> will become a
17836-
separate element in the array.
17837-
If <parameter>delimiter</parameter> is an empty string, then
17838-
the <parameter>string</parameter> is treated as a single field.
17839-
If <parameter>null_string</parameter> is supplied and is
17840-
not <literal>NULL</literal>, fields matching that string are converted
17841-
to <literal>NULL</literal> entries.
17842-
</para>
17843-
<para>
17844-
<literal>string_to_array('xx~~yy~~zz', '~~', 'yy')</literal>
17845-
<returnvalue>{xx,NULL,zz}</returnvalue>
17846-
</para></entry>
17847-
</row>
17848-
1784917881
<row>
1785017882
<entry role="func_table_entry"><para role="func_signature">
1785117883
<indexterm>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy