Closed dwelch2344 closed 3 years ago
Thanks for such a great and well formulated improvement!
This is now available in version 5.0.0 Is this working for you as expected?
The regexp responsible for removing comments also removes parts of the query that should be kept in place:
WHERE "domain" = '10YNL----------L'
It's not so easy, if at all possible, to write a regexp that covers the cases where double dashes should not be replaced, so would it be possible to make the replacement optional?
@dwelch2344 not sure whether this got to your attention since it's a closed issue.
First off, great library! Thank you so much – it makes Postgres so awesome to work with :D
TL;DR: SQL Comments can break parsing Postgres queries
Conditions
Two cases identified thus far, but I'll bet there's more:
Background: So, we've used this lib for about 2+ years and have noticed a few issues when dealing with comments. We typically leave behind SQL comments (our queries can be burley) and without digging into it, if we left a named param in a comment (I.e.
-- sometimes include :blah
) then the param counts come out wrong / all hell breaks loose.Finally dug into it today when a totally separate issue appeared: our CTEs were not interpolating. After digging around, realized it wasn't actually the CTE, but because we had a comment on the line above with a single quote.
Reproduction
I threw together a really stupid ugly test to see if I could nail down what it was, and it became pretty clear. Try the following:
Ghetto, I know. But shows the issue.
Proposed solution
Ignoring comments all together seems like a pretty legit idea. Was looking at the PG specific code, and having something to cut lines starting at
--
probably wouldn't be bad (and would be pretty safe).Multi-lines is a whole other ball of wax... but I want to try to exclude those as well - and if it's not an easy win, just put a disclaimer on those :)
Final Thoughts
Happy to contribute a solution, however you think it best fixed. Thanks!