Introduction
Theformat_sql function converts the structured dictionary produced by parse_sql back into a SQL string. Use it to normalize SQL formatting, validate that a parsed query round-trips correctly, or reconstruct a SQL statement after modifying its parsed representation.
format_sql is most useful as the second step in a parse-then-reconstruct pipeline: first parse a SQL string into a structured dictionary with parse_sql, optionally inspect or transform the result, and then call format_sql to produce a clean, normalized SQL string.
For users of other query languages
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.Splunk SPL users
Splunk SPL users
Splunk has no equivalent to
format_sql. There is no native way in SPL to reconstruct a SQL string from a parsed representation. In APL, format_sql takes the output of parse_sql and reconstructs the original SQL statement.ANSI SQL users
ANSI SQL users
ANSI SQL has no built-in function to reconstruct a SQL string from a parsed representation.
format_sql is unique to APL and works as the inverse of parse_sql.Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| parsed_sql_model | dictionary | Yes | The structured data model returned by parse_sql. |
Returns
A string containing the SQL statement reconstructed from the provided data model.Example
Parse a SQL query representing a slow-query log entry and reconstruct it to verify the round-trip. Queryformat_sql, confirming that the parse-and-reconstruct pipeline preserves the original statement’s structure.
List of related functions
- parse_sql: Parses a SQL statement string into a structured dictionary.
format_sqlis the inverse ofparse_sql. - parse_json: Parses a JSON string into a dynamic dictionary. Use
parse_jsonwhen your data contains JSON rather than SQL.