dbcli / pgcli

Postgres CLI with autocompletion and syntax highlighting
http://pgcli.com
BSD 3-Clause "New" or "Revised" License
12.11k stars 557 forks source link

Not able to submit a query in multiline mode #1100

Open snuyanzin opened 5 years ago

snuyanzin commented 5 years ago

Description

Sometimes while multiline mode it is impossible to submit a query with single quotes inside multiline comments. After playing with that I was able to find a simple query to reproduce

select 1 /*'/* */'*/
;

Moreover it is impossible to finish editing this query (the only option I found is CTRL+C)

At the same time in case one-line mode the same query is submitted successfully

select 1 /*'/* */'*/
+------------+
| ?column?   |
|------------|
| 1          |
+------------+
SELECT 1
Time: 0.024s

Your environment

owst commented 5 years ago

Thanks for the report @snuyanzin.

The example is a bit tricky, since I don't think C-style comments can be nested, so the query actually does contain an unmatched ' as the first one is commented out. As I understand it:

select 
1 
/*'/* */ <- comment ends after first */
'*/      <- this ' is unmatched
;

Do you have another example without nested multi-line comment delimiters that exhibits the problem?

Without looking into it, I wonder if it's possible to indicate after pressing Enter that the query wasn't executed due to an unmatched quote, which might help identify issues like this a bit more clearly, rather than Enter seemingly not working

snuyanzin commented 5 years ago

I don't think C-style comments can be nested

according postgresql documentation it could be https://www.postgresql.org/docs/8.0/sql-syntax.html#SQL-SYNTAX-COMMENTS

there are a number of other more complicated examples with such comments. Here I just posted the simplest one. If it helps I could provide others

owst commented 5 years ago

Thanks for the link @snuyanzin - I didn't know about this feature of C-style comments in SQL!

Having looked into it a bit more, the cause of this issue is a bug in the sqlparse library that we use - I've commented with some background on the open issue regarding nested comments https://github.com/andialbrecht/sqlparse/issues/410#issuecomment-547688075 and I had a quick look at the sqlparse code, but it wasn't going to be a quick fix for me to make.