quote
You can use quote to:
- Safely format strings for output or reuse.
- Prevent syntax errors when generating queries dynamically.
- Inspect values that contain special or unexpected characters.
Use this function when you need to serialize a string value exactly as it would appear in an APL query.
Usage#
Syntax#
quote(value)Parameters#
| Name | Type | Description |
|---|---|---|
| value | string | The value to quote and escape |
Returns#
A string value representing the input enclosed in double quotes, with internal quotes and escape sequences handled appropriately.
Use case examples#
In log analysis, you might want to safely quote URI strings for inclusion in alerts or dashboards.
Query
['sample-http-logs']
| where method == 'POST'
| summarize count() by quoted_uri = quote(uri)Output
| quoted_uri | count_ |
|---|---|
| "/api/login" | 83 |
| "/api/purchase" | 61 |
| "/search?q%3Derror" | 12 |
This query quotes the URI paths in log entries, ensuring that any special characters are preserved in output.
In OpenTelemetry traces, quoting service.name values helps safely display or export the names in logs or dashboards where special characters could otherwise break formatting.
Query
['otel-demo-traces']
| summarize count() by quoted_service = quote(['service.name'])Output
| quoted_service | count_ |
|---|---|
| "frontend" | 1041 |
| "checkoutservice" | 853 |
| "productcatalogservice" | 790 |
The query quotes service names for safe export or logging.
Other query languages#
Splunk SPL users
Splunk doesn’t provide a direct equivalent to quote. However, you can use tostring() or replace() combinations to prepare literal-safe outputs, although escaping and quoting must often be handled manually.
Splunk example
| eval quoted_value="'" . replace(myfield,"'","\\'") . "'"APL equivalent
datatable(s:string)
[
'O\'Reilly',
'simple'
]
| extend quoted = quote(s)ANSI SQL users
ANSI SQL does not have a direct quote() function. You typically handle quoting and escaping manually using REPLACE() or CONCAT() to build quoted strings, which can be error-prone for nested or dynamic queries.
SQL example
SELECT CONCAT('''', REPLACE(name, '''', ''''''), '''') AS quoted_name FROM authors;APL equivalent
datatable(name:string)
[
'O\'Reilly',
'simple'
]
| extend quoted_name = quote(name)