sql() params don't work in fields or tables list
Opened this issue · 3 comments
select('id', 'title', sql('ts_rank(tsv, plainto_tsquery($))', search))
.from('place').where(...)
// SELECT id, title, ts_rank(tsv, plainto_tsquery($)) FROM place ...
select().from('place', sql('plainto_tsquery($) as query', search))
.where(sql('tsv @@ query'))
// SELECT * FROM place, plainto_tsquery($) as query WHERE tsv @@ plainto_tsquery
Any news on this?
@Suor: I recently went through the open issues & marked some easy ones as good first bug
and bigger or non-backwards compatible ones with the 3.0
milestone. This is the only one that didn't fall into either camp.
I suspect it's not trivial, but not super-hard either, and I was hoping to make time to tackle it within the next few months. If you have time and inclination before then, a pull request would be welcome -- or if you just want to do some initial digging and see where the problem is or where the code will likely need to be changed.
I just ran in to this when trying to do substitutions for selects with postgis. I don't know if it's any easier, but a utility function to just do a simple value replacement would be a workable alternative.
To use the the original example, I was thinking something like this, where sql.replace
just does the string substitutions (without messing with the value indexes).
select('id', 'title', replace('ts_rank(tsv, plainto_tsquery($))', search))
.from('place').where(...)