Practical developer guides

SQL formatting does not validate queries or prevent injection

Use formatting to review a query and prepared parameters to handle values safely in the real database client.

Nav Tools ·

Formatting improves readability

Indentation and keyword layout make a query easier to inspect. They do not prove that tables exist, types match or the query is authorized.

Select the relevant SQL dialect in the formatter. Syntax accepted by one database may be rejected or mean something different in another.

Parameterize values

Prepared statements separate SQL structure from data values. Use the database client’s supported placeholder syntax rather than concatenating user input.

The example uses a question-mark placeholder as an illustration. PostgreSQL and other clients may use different placeholders or binding APIs.

SELECT id, name
FROM users
WHERE email = ?;
Bind the email value with the database client.

Identifiers need a separate policy

Ordinary bound parameters represent values, not arbitrary table names, column names or sort directions. Those structural choices need an allowlist or a safe query builder.

Escaping or pretty-printing a complete string does not establish that policy. Review how each dynamic query part enters the final statement.

Generated exports need review

JSON-to-SQL can prepare statements for data transfer, but output still needs review against the destination schema and dialect. It is not automatically a live database command.

Test with a disposable dataset and a transaction when appropriate. Check constraints, identifiers, null handling and row counts before using the export.

References

← Practical developer guides