embed_sql_params

Description

Embed parameters into the given prepared SQL statement by replacing occurrences of the placeholder character ‘?’ with values from the input arguments array. This can be helpful with analyzing SQL statement logs by making them more readable. Note that the function will correctly skip ‘?’ that appear in a quoted string.

If the number of elements in the array does not match the number of ‘?’ placeholders to replace, this function returns null.

Return type

string

Domain

This is a scalar function (calculates a single output value for a single input row.)

Categories

Usage

embed_sql_params(statement, arguments)

Argument

Type

Optional

Repeatable

Restrictions

statement

string

no

no

none

arguments

array

no

no

none

Examples

embed_sql_params
    "SELECT * FROM employees WHERE name LIKE ? AND age BETWEEN ? AND ?",
    make_array("David?", 18, 60)

Replace the placeholder “?” in the given statement with the given arguments and return the following SQL statement:

SELECT * FROM employees WHERE name LIKE 'David?' AND age BETWEEN 18 AND 60