concat()

The concat() function concatenates one or more arguments in order and returns them as a single string.

Syntax

concat(VALUE1[, VALUE2, ...])

Parameters

VALUE1, VALUE2, ...
The values to concatenate. Two or more arguments can be specified, with no limit on the number of arguments.

Description

The concat() function converts each argument using toString() and concatenates them in order to return a string. Any null values among the arguments are ignored and not included in the concatenation. Even if all arguments are null, an empty string ("") is returned.

Error codes

N/A

Usage examples

To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.

  1. Concatenate HTTP method and URI to form a request string

    table limit=5 WEB_APACHE_SAMPLE | eval result = concat(method, " ", uri) | fields method, uri, result
    | # result: "GET /feed", etc.
    
  2. Concatenate HTTP method, URI, and protocol to reconstruct the request line

    table limit=5 WEB_APACHE_SAMPLE | eval result = concat(method, " ", uri, " ", protocol) | fields result
    | # result: "GET /feed HTTP/1.1", etc.
    
  3. Null arguments are ignored

    json "{'a': 'foo', 'b': null, 'c': 'bar'}" | eval result = concat(a, b, c)
    | # result: "foobar"
    
  4. All arguments are null

    json "{'a': null}" | eval result = concat(a)
    | # result: ""
    

Compatibility

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