split_by_string

description

Syntax

  1. split_by_string(s, separator)

Splits a string into substrings separated by a string. It uses a constant string separator of multiple characters as the separator. If the string separator is empty, it will split the string s into an array of single characters.

Arguments

separator — The separator. Type: String

s — The string to split. Type: String

Returned value(s)

Returns an array of selected substrings. Empty substrings may be selected when:

A non-empty separator occurs at the beginning or end of the string;

There are multiple consecutive separators;

The original string s is empty.

Type: Array(String)

notice

Only supported in vectorized engine

example

  1. SELECT split_by_string('1, 2 3, 4,5, abcde', ', ');
  2. select split_by_string('a1b1c1d','1');
  3. +---------------------------------+
  4. | split_by_string('a1b1c1d', '1') |
  5. +---------------------------------+
  6. | ['a', 'b', 'c', 'd'] |
  7. +---------------------------------+
  8. select split_by_string(',,a,b,c,',',');
  9. +----------------------------------+
  10. | split_by_string(',,a,b,c,', ',') |
  11. +----------------------------------+
  12. | ['', '', 'a', 'b', 'c', ''] |
  13. +----------------------------------+
  14. SELECT split_by_string(NULL,',');
  15. +----------------------------+
  16. | split_by_string(NULL, ',') |
  17. +----------------------------+
  18. | NULL |
  19. +----------------------------+
  20. select split_by_string('a,b,c,abcde',',');
  21. +-------------------------------------+
  22. | split_by_string('a,b,c,abcde', ',') |
  23. +-------------------------------------+
  24. | ['a', 'b', 'c', 'abcde'] |
  25. +-------------------------------------+
  26. select split_by_string('1,,2,3,,4,5,,abcde', ',,');
  27. +---------------------------------------------+
  28. | split_by_string('1,,2,3,,4,5,,abcde', ',,') |
  29. +---------------------------------------------+
  30. | ['1', '2,3', '4,5', 'abcde'] |
  31. +---------------------------------------------+
  32. select split_by_string(',,,,',',,');
  33. +-------------------------------+
  34. | split_by_string(',,,,', ',,') |
  35. +-------------------------------+
  36. | ['', '', ''] |
  37. +-------------------------------+
  38. select split_by_string(',,a,,b,,c,,',',,');
  39. +--------------------------------------+
  40. | split_by_string(',,a,,b,,c,,', ',,') |
  41. +--------------------------------------+
  42. | ['', 'a', 'b', 'c', ''] |
  43. +--------------------------------------+

keywords

SPLIT_BY_STRING,SPLIT