Wrong number of params with sub query?
barbogast opened this issue · 2 comments
barbogast commented
First of all, great library, thanks a lot :)
When using sub queries and joining them to tables toParams()
seems to return parameters in the sub query twice:
sql
.select()
.from(sql.select().from('a').where('x', 'y').as('b'))
.join('c', {'c.id': 'b.id'})
.toParams()
prints this:
{
text: 'SELECT * FROM (SELECT * FROM a WHERE x = $1) b INNER JOIN c ON c.id = b.id',
values: [ 'y', 'y' ]
}
Expected:
{
text: 'SELECT * FROM (SELECT * FROM a WHERE x = $1) b INNER JOIN c ON c.id = b.id',
values: [ 'y']
}
prust commented
@Koblaid: thank you for reporting this! I fixed it in #80 (though it is possible that there may be lingering deeper issues) and published to npm as v1.2.3.
Thanks also for the detailed code and actual vs expected output, I was able to easily convert that into a failing test and add it to our test suite, which makes life easier for me & makes me happy :-)
barbogast commented
Wow, that was quick, thanks a lot. I also enjoyed a lot reading your answer :-)