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

Commit8118686

Browse files
committed
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 changesthe name of split(text,text,int) to split_part(text,text,int) perHannu's recommendation above. This can be applied without an initdb ifcurrent 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 isalso included in the patch.Joe Conway
1 parente04069f commit8118686

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

‎doc/src/sgml/func.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.121 2002/09/11 02:56:46 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/func.sgml,v 1.122 2002/09/12 00:21:24 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -1899,14 +1899,14 @@ PostgreSQL documentation
18991899
</row>
19001900

19011901
<row>
1902-
<entry><function>split</function>(<parameter>string</parameter> <type>text</type>,
1902+
<entry><function>split_part</function>(<parameter>string</parameter> <type>text</type>,
19031903
<parameter>delimiter</parameter> <type>text</type>,
19041904
<parameter>column</parameter> <type>integer</type>)</entry>
19051905
<entry><type>text</type></entry>
19061906
<entry>Split <parameter>string</parameter> on <parameter>delimiter</parameter>
19071907
returning the resulting (one based) <parameter>column</parameter> number.
19081908
</entry>
1909-
<entry><literal>split('abc~@~def~@~ghi','~@~',2)</literal></entry>
1909+
<entry><literal>split_part('abc~@~def~@~ghi','~@~',2)</literal></entry>
19101910
<entry><literal>def</literal></entry>
19111911
</row>
19121912

‎src/include/catalog/pg_proc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.270 2002/09/04 20:31:38 momjian Exp $
10+
* $Id: pg_proc.h,v 1.271 2002/09/12 00:21:24 momjian Exp $
1111
*
1212
* NOTES
1313
* 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
21302130
DESCR("return portion of string");
21312131
DATA(insertOID=2087 (replacePGNSPPGUID12fftfi325"25 25 25"replace_text-_null_ ));
21322132
DESCR("replace all occurrences of old_substr with new_substr in string");
2133-
DATA(insertOID=2088 (splitPGNSPPGUID12fftfi325"25 25 23"split_text-_null_ ));
2133+
DATA(insertOID=2088 (split_partPGNSPPGUID12fftfi325"25 25 23"split_text-_null_ ));
21342134
DESCR("split string by field_sep and return field_num");
21352135
DATA(insertOID=2089 (to_hexPGNSPPGUID12fftfi125"23"to_hex32-_null_ ));
21362136
DESCR("convert int32 number to hex");

‎src/test/regress/expected/strings.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -719,29 +719,29 @@ SELECT replace('yabadoo', 'bad', '') AS "yaoo";
719719
(1 row)
720720

721721
--
722-
-- testsplit
722+
-- testsplit_part
723723
--
724-
selectsplit('joeuser@mydatabase','@',0) AS "an error";
724+
selectsplit_part('joeuser@mydatabase','@',0) AS "an error";
725725
ERROR: field position must be > 0
726-
selectsplit('joeuser@mydatabase','@',1) AS "joeuser";
726+
selectsplit_part('joeuser@mydatabase','@',1) AS "joeuser";
727727
joeuser
728728
---------
729729
joeuser
730730
(1 row)
731731

732-
selectsplit('joeuser@mydatabase','@',2) AS "mydatabase";
732+
selectsplit_part('joeuser@mydatabase','@',2) AS "mydatabase";
733733
mydatabase
734734
------------
735735
mydatabase
736736
(1 row)
737737

738-
selectsplit('joeuser@mydatabase','@',3) AS "empty string";
738+
selectsplit_part('joeuser@mydatabase','@',3) AS "empty string";
739739
empty string
740740
--------------
741741

742742
(1 row)
743743

744-
selectsplit('@joeuser@mydatabase@','@',2) AS "joeuser";
744+
selectsplit_part('@joeuser@mydatabase@','@',2) AS "joeuser";
745745
joeuser
746746
---------
747747
joeuser

‎src/test/regress/sql/strings.sql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,17 @@ SELECT replace('yabadabadoo', 'ba', '123') AS "ya123da123doo";
288288
SELECT replace('yabadoo','bad','')AS"yaoo";
289289

290290
--
291-
-- testsplit
291+
-- testsplit_part
292292
--
293-
selectsplit('joeuser@mydatabase','@',0)AS"an error";
293+
selectsplit_part('joeuser@mydatabase','@',0)AS"an error";
294294

295-
selectsplit('joeuser@mydatabase','@',1)AS"joeuser";
295+
selectsplit_part('joeuser@mydatabase','@',1)AS"joeuser";
296296

297-
selectsplit('joeuser@mydatabase','@',2)AS"mydatabase";
297+
selectsplit_part('joeuser@mydatabase','@',2)AS"mydatabase";
298298

299-
selectsplit('joeuser@mydatabase','@',3)AS"empty string";
299+
selectsplit_part('joeuser@mydatabase','@',3)AS"empty string";
300300

301-
selectsplit('@joeuser@mydatabase@','@',2)AS"joeuser";
301+
selectsplit_part('@joeuser@mydatabase@','@',2)AS"joeuser";
302302

303303
--
304304
-- test to_hex

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp