Force detection of SQL query

When one has a query that starts with a complex table expression (WITH), it looks like the IDE won't auto-detect the string as a SQL query.

Is there a way to make it do the proper detection (annotation in code, or some IDE setting change)?

sample Python code with the query would be something like this

sql = """with cte as (select foo from bar)
select * from cte"""
1
4 comments

Although the same query you attached is automatically detected for me as sql fragment, you can use Alt+Enter Intention action to inject the language in a string literal:

Please check also https://www.jetbrains.com/pycharm/help/using-language-injections.html .

1

I'm on PHPStorm 2017.2.4 with the IntelliLang plugin enabled

Going to Settings->Editor-Language Injections lets you modify how the default matching works. (first image)

It appears to use regex. I've added a check for when i DECLARE sql variables in a string literal before SELECTing. (second image)



1

I modified the regex as following:

["'`] *(((WITH .*AS.*\()|(SELECT|DELETE) .*FROM)|((INSERT|REPLACE) .*INTO)|(UPDATE .* SET)|((CREATE|DROP|ALTER) +((TEMPORARY )?TABLE|(UNIQUE )?INDEX))) .*["'`]?

and now it accepts the With syntax

0

Please sign in to leave a comment.