Example query:
sql, params := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar).
Select("*").
PrefixExpr(
squirrel.StatementBuilder.
Select("time").
From("smurfs").
Where("id = ?", "x").
Prefix("WITH a AS (").Suffix(")"),
).
From("a").
Where("time > ?", time.Now()).
MustSql()
This generates the following SQL (reformatted for eligibility):
WITH a AS (
SELECT time FROM smurfs WHERE id = $1
)
SELECT * FROM a WHERE time > $1
with parameters:
["x", "2021-05-21 13:27:32.380139 +0200"]
Obviously this should be:
WITH a AS (
SELECT time FROM smurfs WHERE id = $1
)
SELECT * FROM a WHERE time > $2
Unfortunate workaround (not tested):
q1, p1 := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar).
Select("time").
From("document_changes").
Where("id = ?", "x").
Prefix("WITH a AS (").Suffix(")").
MusSql()
q2, p2 := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar).
Select("*").
Prefix(q1).
From("a").
Where("time > ?", time.Now()).
MustSql()
sql := q1 + q2
params := append(p1, p2...)
Presumably the bug also affects SuffixExpr().
Example query:
This generates the following SQL (reformatted for eligibility):
with parameters:
Obviously this should be:
Unfortunate workaround (not tested):
Presumably the bug also affects
SuffixExpr().