pgcli
pgcli copied to clipboard
stripping comments
Hello,
I am tagging queries and I was using pgcli to exec them, things like this:
/* TEST123 TAGGING */ select 1
it looks to me that pgcli does not send /* */ or -- comments to the backend. Is this the desired behaviour?
We explicitly strip comments before passing the SQL on to psycopg2:
https://github.com/dbcli/pgcli/blob/c65495716d9fa6914f689d410d3c737d7661053d/pgcli/pgexecute.py#L433
What's the use case for keeping the comments?
I'd been asking the same question...
I have been analyzing pretty big queries recently and in postgres there is a postgresql.conf log feature set
auto_explain.
With that you can tune pg to automatically log the whole execution plan each time the query is executed (eventually splitting it in sub queries, etc).
While doing this it also logs all the comments that were included in SQL.
These comments can then be used to match "query part" <----> "execution plan" in this enormous log files.
And they are also used by some tools doing this automatically, like https://pganalyze.com/postgres-analyze-query-performance
TIL. I believe that psycopg2 can execute SQL queries with comments in them, it should be easy enough to remove comment stripping in a branch and see what happens. I don't have the bandwidth to do this right now, so I'll leave the issue open as an enhancement request, or feel free to submit a PR yourself.
...so I will not be able to proudly say that I have never written a line of python in my life. Ok I guess time for a change :)