Using language injections in SQL
For language injections in SQL, PhpStorm provides the following additional features (for general info, see Using Language Injections):
- Auto-injection for XML and JSON data types, see Using auto-injection for XML and JSON.
- Data type patterns, see Using pattern-based injections for user-defined data types.
Using auto-injection for XML and JSON
For values defined as XML and JSON types, the corresponding languages are injected automatically.
- Create an SQL file and open it in the editor.
- Specify PostgreSQL as an SQL dialect for that file.
-
Copy the following into your SQL file:
CREATE TABLE test ( my_xml XML DEFAULT '' );
- Place the cursor between the quotation marks.
- Check the light bulb menu (Alt+Enter): there is the Edit XML Fragment command there which means that XML has been auto-injected.
Using pattern-based injections for user-defined data types
You can create patterns - e.g. for user-defined data types - and associate those patterns with languages. As a result, PhpStorm, when it comes across a data type that matches the pattern, will inject the language specified for that pattern.
In the following example, we'll create a pattern for a data type ending in DATA
and
associate that pattern with XML.
-
In your SQL file, replace
XML
withMYDATA
. - Place the cursor between the quotation marks.
- Press Alt+Enter. Note that there is no more Edit XML Fragment command in the menu.
-
In the dialog that opens, in the Type pattern field,
specify
(?i).*DATA
. (The type patterns are specified using regular expressions. In this example,(?i)
turns the case-insensitive mode on;.*
stands for any number of any characters.) -
Check the light bulb menu again (Alt+Enter).
The Edit XML Fragment command has become available which means that
XML has been injected for the value of the
MYDATA
type. - To remove the pattern you have just created (if you don't need it), open the Settings / Preferences dialog (e.g. Ctrl+Alt+S), go to the page, find and delete the pattern.
See Also
Procedures:
Last modified: 23 March 2017