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"""

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 .


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)


I modified the regex as following:


and now it accepts the With syntax


Please sign in to leave a comment.