Add split function

Completed

Comments

3 comments

  • Comment actions Permalink
    Official comment
    Avatar
    Niklas Schmidtmer

    Hi all,

     

    I'm happy to report that we now released the SPLIT_PART function as part of LDW 2.3.8.

     

    Best

     

    Niklas

  • 0
    Comment actions Permalink
    Avatar
    Salvatore Raunich

    Hi Carly,

    actually this feature was also requested by many other customers and we are planning to include it in one of the next minors.

    I will follow up on your request as soon as this new feature will be officially released.

    Thanks for using our online community.

    Best,

    Salvatore

  • 0
    Comment actions Permalink
    Avatar
    Daniel Scholten

    Here is a split function implemented as a user-defined procedure. It is implemented quite quick and dirty, for example i did not try what happens if Input is NULL. But you dont need javascript. Usage example:

    call "mySchema.split"(
    "string_to_split" => 'foobar',
    "split_expression" => 'o'
    );;
    CREATE procedure "mySchema"."split" (
    IN string_to_split string not null Options (Annotation 'string to split'),
    IN split_expression string not null Options (Annotation 'expression where to split the string')
    ) RETURNS (
    array_of_strings object
    ) Options (Annotation 'Split a string at a given expression. Example: split(foobar, o) -> [f, bar]')as
    begin
    declare object array_of_strings = array();
    declare string rest_of_string = string_to_split;
    declare string first_part;
    declare string second_part;

    while (locate(split_expression, rest_of_string) > 0)
    begin
    first_part = substring(rest_of_string from 1 for (locate(split_expression, rest_of_string) - 1)); /* kann leerer String sein */
    second_part = substring(rest_of_string, locate(split_expression, rest_of_string) + length(split_expression)); /* kann null sein */
    if (first_part <> '') /* erste Zeichen von rest_of_string sind nicht die split_expression */
    begin
    array_of_strings = array_add(array_of_strings, first_part);
    end
    rest_of_string = second_part;
    end

    if (rest_of_string is not null) /* erste Zeichen von rest_of_string sind nicht die split_expression */
    begin
    array_of_strings = array_add(array_of_strings, rest_of_string);
    end

    /* Leerer Input-String -> Leeres Array */
    if (length(string_to_split) = 0)
    begin
    select array();
    end

    select
    array_of_strings;
    end;

Please sign in to leave a comment.

Powered by Zendesk