pgcli icon indicating copy to clipboard operation
pgcli copied to clipboard

stripping comments

Open edoardoc opened this issue 4 years ago • 4 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?

edoardoc avatar Sep 08 '21 17:09 edoardoc

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?

j-bennet avatar Sep 27 '21 22:09 j-bennet

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

edoardoc avatar Oct 03 '21 14:10 edoardoc

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.

j-bennet avatar Oct 04 '21 20:10 j-bennet

...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 :)

edoardoc avatar Oct 08 '21 16:10 edoardoc