Postfix completion
With postfix templates, you can transform an already-typed expression to a different one based on a postfix after the dot, the type of the expression, and its context. DataGrip includes a set of predefined postfix completion templates that you can use for other programming languages as well. You can copy, enable, and disable these templates.
Enable and configure postfix completion
In the Settings dialog (Ctrl+Alt+S), open and select the Enable postfix completion checkbox.
Enable or disable postfix templates for the selected language.
Set the Tab, Space, or Enter key to expand postfix templates.
Transform a statement with a postfix
Type an expression and then type a postfix after a dot.
Press Tab.
Postfix completion options are shown as part of the basic completion suggestion list. To see a full list of postfix completions applicable in the current context, press Ctrl+J.
DataGrip includes the following predefined templates:
Template | Before | After |
---|---|---|
| SELECT actor.from | SELECT ...
FROM actor |
| SELECT actor.cfrom | SELECT actor_id,
first_name,
last_name,
last_update
FROM actor |
| SELECT actor.afrom | SELECT
actor_id AS ai,
first_name AS fn,
last_name AS ln,
last_update AS lu
FROM actor |
| SELECT actor.cast | SELECT cast(actor AS ...) |
| SELECT actor.join | SELECT * FROM actor
JOIN film_actor fa
ON actor.actor_id = fa.actor_id
|
Edit a postfix template name
You can edit the predefined postfix templates, for example, to replace a long key with a shorter one, or to expand the list of applicable expression types.
Press Ctrl+Alt+S to open settings and then select
.Double-click a template name in the tree or click the
icon above the list of templates and edit it as required.
Create custom postfix templates
Press Ctrl+Alt+S to open settings and then select
.Click the Add button (
) on the toolbar and select SQL.
In the Create New Template dialog that opens, specify Key, a combination of symbols after the dot that will invoke the template.
Select which dialects the new template will be applicable to, and type the target expression in the following format:
$EXPR$ <target_expression>
, for example,* FROM $EXPR$;
.
Share postfix templates
You can share postfix templates in the following ways:
Use the Backup and Sync plugin to synchronize templates and their settings between IDEs.
Manually export postfix templates from one IDE and import them into another IDE.
Postfix vs. live templates
Postfix code completion is similar to live templates which allow you to create custom constructs to be used anywhere inside your code.
The difference is that live templates insert predefined code snippets, while postfix completion wraps or modifies existing expressions.