Description
In v2.15.0, CustomExpression now parenthesizes sub-expressions (related to the IS_NOT_NULL parenthesization fix). This breaks the pattern of nesting DISTINCT(column) inside CustomExpression for aggregate ORDER BY clauses.
Reproducer
nameColumn := pg.StringColumn("name")
people := pg.NewTable("public", "people", "", nameColumn)
expr := pg.CustomExpression(pg.DISTINCT(nameColumn), pg.Token("ORDER BY"), nameColumn)
agg := pg.Func("array_agg", expr)
stmt := pg.SELECT(agg.AS("names")).FROM(people)
q, _ := stmt.Sql()
fmt.Println(q)
v2.14.1 (correct)
SELECT array_agg(DISTINCT people.name ORDER BY people.name) AS "names"
FROM public.people;
v2.15.0 (broken)
SELECT array_agg((DISTINCT people.name) ORDER BY people.name) AS "names"
FROM public.people;
The extra parentheses around DISTINCT people.name produce a SQL syntax error:
pq: syntax error at or near "DISTINCT" at position 2:19 (42601)
Workaround
Use Token("DISTINCT") instead of DISTINCT():
expr := pg.CustomExpression(pg.Token("DISTINCT"), nameColumn, pg.Token("ORDER BY"), nameColumn)
This produces correct SQL because Token is not parenthesized.
Environment
- jet v2.15.0
- PostgreSQL 18.1
Description
In v2.15.0,
CustomExpressionnow parenthesizes sub-expressions (related to the IS_NOT_NULL parenthesization fix). This breaks the pattern of nestingDISTINCT(column)insideCustomExpressionfor aggregate ORDER BY clauses.Reproducer
v2.14.1 (correct)
v2.15.0 (broken)
The extra parentheses around
DISTINCT people.nameproduce a SQL syntax error:Workaround
Use
Token("DISTINCT")instead ofDISTINCT():This produces correct SQL because
Tokenis not parenthesized.Environment