strjoin()

The strjoin() function joins each element of an array with a specified separator and returns the result as a single string.

Syntax

strjoin(SEPARATOR, ARRAY)

Parameters

SEPARATOR
A string constant to insert between each element of the array. Non-constant expressions are not allowed.
ARRAY
The array field or expression to join.

Description

The strjoin() function returns a string formed by joining the elements of ARRAY with SEPARATOR between each element.

  • If ARRAY is null, the function returns null.
  • If ARRAY is not an array or list, the function returns null.
  • If any element in the array is null, the string "null" is included at that position.
  • If a non-constant expression is specified for SEPARATOR, error code 90781 is raised.
  • If more than two arguments are provided, error code 90780 is raised.

Error codes

Error codeDescription
90780More than two arguments were provided.
90781A non-constant expression was specified for SEPARATOR.

Usage examples

  1. Join a numeric array

    json "{}" | eval result = strjoin(",", array(1, 2, 3))
    | # result: "1,2,3"
    
  2. Join a string array

    json "{'tags': ['a', 'b', 'c']}" | eval result = strjoin(" | ", tags)
    | # result: "a | b | c"
    
  3. NULL input

    json "{'arr': null}" | eval result = strjoin(",", arr)
    | # result: null
    

Compatibility

The strjoin() function is available since before Sonar 4.0.