]> granicus.if.org Git - postgresql/commitdiff
Joe Conway wrote:
authorBruce Momjian <bruce@momjian.us>
Thu, 12 Sep 2002 00:21:25 +0000 (00:21 +0000)
committerBruce Momjian <bruce@momjian.us>
Thu, 12 Sep 2002 00:21:25 +0000 (00:21 +0000)
 > Hannu Krosing wrote:
 >
 >> It seems that my last mail on this did not get through to the list
 >> ;(
 >>
 >> Please consider renaming the new builtin function
 >> split(text,text,int)
 >>
 >> to something else, perhaps
 >>
 >> split_part(text,text,int)
 >>
 >> (like date_part)
 >>
 >> The reason for this request is that 3 most popular scripting
 >> languages (perl, python, php) all have also a function with similar
 >> signature, but returning an array instead of single element and the
 >> (optional) third argument is limit (maximum number of splits to
 >> perform)
 >>
 >> I think that it would be good to have similar function in (some
 >> future release of) postgres, but if we now let in a function with
 >> same name and arguments but returning a single string instead an
 >> array of them, then we will need to invent a new and not so easy to
 >> recognise name for the "real" split function.
 >>
 >
 > This is a good point, and I'm not opposed to changing the name, but
 > it is too bad your original email didn't get through before beta1 was
 >  rolled. The change would now require an initdb, which I know we were
 >  trying to avoid once beta started (although we could change it
 > without *requiring* an initdb I suppose).
 >
 > I guess if we do end up needing an initdb for other reasons, we
 > should make this change too. Any other opinions? Is split_part an
 > acceptable name?
 >
 > Also, if we add a todo to produce a "real" split function that
 > returns an array, similar to those languages, I'll take it for 7.4.

No one commented on the choice of name, so the attached patch changes
the name of split(text,text,int) to split_part(text,text,int) per
Hannu's recommendation above. This can be applied without an initdb if
current beta testers are advised to run:

   update pg_proc set proname = 'split_part' where proname = 'split';

in the case they want to use this function. Regression and doc fix is
also included in the patch.

Joe Conway

doc/src/sgml/func.sgml
src/include/catalog/pg_proc.h
src/test/regress/expected/strings.out
src/test/regress/sql/strings.sql

index 6ffde9e5296d2b55c564e6a0a5a9b7d16763e142..054d495a927cf23dd68114e3b13bdc13fe5e72eb 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.121 2002/09/11 02:56:46 momjian Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.122 2002/09/12 00:21:24 momjian Exp $
 PostgreSQL documentation
 -->
 
@@ -1899,14 +1899,14 @@ PostgreSQL documentation
       </row>
 
       <row>
-       <entry><function>split</function>(<parameter>string</parameter> <type>text</type>,
+       <entry><function>split_part</function>(<parameter>string</parameter> <type>text</type>,
        <parameter>delimiter</parameter> <type>text</type>,
        <parameter>column</parameter> <type>integer</type>)</entry>
        <entry><type>text</type></entry>
        <entry>Split <parameter>string</parameter> on <parameter>delimiter</parameter>
         returning the resulting (one based) <parameter>column</parameter> number.
        </entry>
-       <entry><literal>split('abc~@~def~@~ghi','~@~',2)</literal></entry>
+       <entry><literal>split_part('abc~@~def~@~ghi','~@~',2)</literal></entry>
        <entry><literal>def</literal></entry>
       </row>
 
index 6e351df0415c1c9d4b817ed9bb2ace00c046b5d1..ff2200d2cc000dd6bef096b659416a2ae4f0a391 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pg_proc.h,v 1.270 2002/09/04 20:31:38 momjian Exp $
+ * $Id: pg_proc.h,v 1.271 2002/09/12 00:21:24 momjian Exp $
  *
  * NOTES
  *       The script catalog/genbki.sh reads this file and generates .bki
@@ -2130,7 +2130,7 @@ DATA(insert OID =  937 (  substring    PGNSP PGUID 12 f f t f i 2 25 "25 23"      tex
 DESCR("return portion of string");
 DATA(insert OID =  2087 ( replace         PGNSP PGUID 12 f f t f i 3 25 "25 25 25"  replace_text - _null_ ));
 DESCR("replace all occurrences of old_substr with new_substr in string");
-DATA(insert OID =  2088 ( split                   PGNSP PGUID 12 f f t f i 3 25 "25 25 23"  split_text - _null_ ));
+DATA(insert OID =  2088 ( split_part   PGNSP PGUID 12 f f t f i 3 25 "25 25 23"  split_text - _null_ ));
 DESCR("split string by field_sep and return field_num");
 DATA(insert OID =  2089 ( to_hex          PGNSP PGUID 12 f f t f i 1 25 "23"  to_hex32 - _null_ ));
 DESCR("convert int32 number to hex");
index ae0b48590cf5fabef0784e3e4fb74272c5ab69ca..ce81969936c5e1a9355e50d0dbc9ba653200e3b0 100644 (file)
@@ -719,29 +719,29 @@ SELECT replace('yabadoo', 'bad', '') AS "yaoo";
 (1 row)
 
 --
--- test split
+-- test split_part
 --
-select split('joeuser@mydatabase','@',0) AS "an error";
+select split_part('joeuser@mydatabase','@',0) AS "an error";
 ERROR:  field position must be > 0
-select split('joeuser@mydatabase','@',1) AS "joeuser";
+select split_part('joeuser@mydatabase','@',1) AS "joeuser";
  joeuser 
 ---------
  joeuser
 (1 row)
 
-select split('joeuser@mydatabase','@',2) AS "mydatabase";
+select split_part('joeuser@mydatabase','@',2) AS "mydatabase";
  mydatabase 
 ------------
  mydatabase
 (1 row)
 
-select split('joeuser@mydatabase','@',3) AS "empty string";
+select split_part('joeuser@mydatabase','@',3) AS "empty string";
  empty string 
 --------------
  
 (1 row)
 
-select split('@joeuser@mydatabase@','@',2) AS "joeuser";
+select split_part('@joeuser@mydatabase@','@',2) AS "joeuser";
  joeuser 
 ---------
  joeuser
index 2095848a39dbea2d312c5c860c090964a5a439da..692233793dc74c7996601d8ac14149b6e3ac9b32 100644 (file)
@@ -288,17 +288,17 @@ SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo";
 SELECT replace('yabadoo', 'bad', '') AS "yaoo";
 
 --
--- test split
+-- test split_part
 --
-select split('joeuser@mydatabase','@',0) AS "an error";
+select split_part('joeuser@mydatabase','@',0) AS "an error";
 
-select split('joeuser@mydatabase','@',1) AS "joeuser";
+select split_part('joeuser@mydatabase','@',1) AS "joeuser";
 
-select split('joeuser@mydatabase','@',2) AS "mydatabase";
+select split_part('joeuser@mydatabase','@',2) AS "mydatabase";
 
-select split('joeuser@mydatabase','@',3) AS "empty string";
+select split_part('joeuser@mydatabase','@',3) AS "empty string";
 
-select split('@joeuser@mydatabase@','@',2) AS "joeuser";
+select split_part('@joeuser@mydatabase@','@',2) AS "joeuser";
 
 --
 -- test to_hex