简体   繁体   English

如何避免多行SQL文字中的Pycharm检查错误

[英]How to avoid Pycharm inspection error in multiline SQL literals

I recently discovered that PyCharm complains about " expected, unexpected end of file" when I write a SQL Query, that spans multiple lines (using parantheses): 我最近发现,当我编写跨越多行(使用括号)的SQL查询时,PyCharm抱怨“文件的预期末尾意外”:

屏幕截图

It looks like it detects that this is a SQL statement, but only parses the first line. 看起来它检测到这是一条SQL语句,但仅解析第一行。

Any idea how to correctly write this without disabling inspections or writing very long lines ? 任何想法如何正确地写此而不禁用检查或写很长的行?

you need a python multi line string 你需要一个python多行字符串

string = """select * from table
              where x=1
              limit 10"""

if you want to avoid the new lines you can do this: 如果要避免换行,可以这样做:

x = "select * from t " \
    "where x = 1 " \
    "limit 1" 

doc doc

在此处输入图片说明

with sql dialect on: 与SQL方言上:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM