WITH queries don't include the 'AS' keyword
lalitkapoor opened this issue · 1 comments
lalitkapoor commented
const test = sq.from`users`.where({id: 1})
const cte = sq.with({ test }).from`test`.return`id`
console.log(cte.query)
/*
{ text:
'with test (select * from users where (id = $1)) select id from test',
args: [ 1 ],
type: 'select' }
*/
This is not executable by PostgreSQL. adding the AS
keyword makes this query work (with test AS (...) select id from test
), but that's not what is generated with the sq.with
method.
esatterwhite commented
I can confirm, the object notation generates an invalid query.
you can do it with the template tag though
sq.with`test AS ${test}`.from`test`.return`id`