Open michaelborn opened 2 years ago
Note that positional placeholders are still formatted and replace correctly.
Seeing a similar issue with parameter injection, depending on the dialect. When using TSql parameter injection works, when using StandardSql, SparkSql, and maybe others, an extra whitespace is added, and parameter injection does not work:
// Bad example
SqlFormatter.of(Dialect.SparkSql).format("@thing", Map.of("thing", "foo")); // Result: "@ thing"
// Good example
SqlFormatter.of(Dialect.TSql).format("@thing", Map.of("thing", "foo")); // Result: "foo"
If anyone bumps into this issue, a possible workaround is to add '@'
as a named placeholder type:
Formatter sparkSqlFormatter = SqlFormatter
.of(Dialect.SparkSql)
// Required for named placeholders to work
.extend(dialectConfig -> dialectConfig.plusNamedPlaceholderTypes("@"));
// ... any other needed extensions
Name placeholders like
WHERE name = :name
are broken and do not replace at all.Example:
this formats as:
Notice the
=:
and the space between the:
andname
-=: name
You can see this right on the demo page:
https://www.vertical-blank.com/sql-formatter/