From: Bruce Momjian Date: Thu, 12 Sep 2002 00:21:25 +0000 (+0000) Subject: Joe Conway wrote: X-Git-Tag: REL7_3~499 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=81186865fec2e39a6a66e9435b32d7048c03dd32;p=postgresql Joe Conway wrote: > 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 --- diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 6ffde9e529..054d495a92 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -1,5 +1,5 @@ @@ -1899,14 +1899,14 @@ PostgreSQL documentation - split(string text, + split_part(string text, delimiter text, column integer) text Split string on delimiter returning the resulting (one based) column number. - split('abc~@~def~@~ghi','~@~',2) + split_part('abc~@~def~@~ghi','~@~',2) def diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 6e351df041..ff2200d2cc 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -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"); diff --git a/src/test/regress/expected/strings.out b/src/test/regress/expected/strings.out index ae0b48590c..ce81969936 100644 --- a/src/test/regress/expected/strings.out +++ b/src/test/regress/expected/strings.out @@ -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 diff --git a/src/test/regress/sql/strings.sql b/src/test/regress/sql/strings.sql index 2095848a39..692233793d 100644 --- a/src/test/regress/sql/strings.sql +++ b/src/test/regress/sql/strings.sql @@ -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