Named query new placeholder for positionial parameters aggregation
chagui opened this issue · 3 comments
First of all thanks for all the work put in the tooling around pgcli, I am a fan and daily user of pgcli!
When reading the pgcli documentation "Named queries support shell-style parameter substitution." I thought it would be possible to use something like $*
or $@
in named query. That placeholders would be substituted by the aggregation of all parameters (using join?).
Right I am doing it this way
> \ns test select * from t where id IN $1
> \n test "('foo', 'bar')"
but I would find the following cleaner
> \ns test select * from t where id IN ($@)
> \n test 'foo' 'bar'
I believe the changes would be scoped to subst_favorite_query_args (hence reporting the issue in this repos), and I am willing to implement a proposal. What do you think?
@chagui Yes, you are correct, this is the place where parameter substitution happens. If you'd like to extend the functionality, feel free to submit a PR. Thank you!
I opened a pull-request containing a draft proposal for this feature. One tricky part was to allow user to seamlessly both numeric and string values. I made the assumption that all aggregated parameters should be of the same type (which make sense afaik for select ... where col IN (...)
), let me know otherwise.
I was thinking that it would be nice to be able to compose aggregation and positional parameters to do something like this select ... where id = $1 and name in ($@)
. It is possible but would make the implementation more complicated and potentially make it non-obvious for users what is aggregated, they could expect all arguments to be aggregated instead of only the leftovers after positional ones.
Any feedback would be appreciated, thanks!