Closed bjorkegeek closed 1 month ago
Hi @bjorkegeek , thanks for your idea. When you talk about 'tooling' could you give an example of what you mean? Also, I've put a version on the branch https://github.com/tlocke/pg8000/tree/159-add-support-for-valid-sql-statements-with-parameters that lets you use $n style placeholders as well as the :x style ones. The parameters are still keyword parameters, but since Python preserves their order, we can refer to them by position. Anyway, let me know what you think.
I've added this at https://github.com/tlocke/pg8000/commit/46c00021ade1d19466b07ed30392386c5f0a6b8e, but let me know if you have any thoughts on it.
Thanks for considering my feature request. I'm reluctant to use this in my code for two reasons:
I have sent you a third variant for you to consider as a PR. https://github.com/tlocke/pg8000/pull/166
For me the current solution is easy to explain to people. So I can say, 'you specify the parameters as keyword arguments, and then refer to them either by name or position', that's basically all you need to know. It's also immediately obvious how a mixing of styles works. I haven't been able to come up with another method that is as easy to comprehend.
The pg8000 colon syntax for parameters is neat and all... but using it means that the strings passed to Connection.run are not syntactically valid PostgreSQL, which breaks other tooling. I prefer to use the $n placeholders which are considered valid PostgreSQL.
I'm suggesting adding this calling convention
con.run("SELECT 'Hello '||$1;", 'world')
to Connection.runFor the moment I'm monkey patching pg8000 in my project to support this, using the following function:
If the project maintainer agrees to this I can submit a pull request.