DataGrip 2023.1 Help

Context live templates

Context live templates is a solution for anyone who wants to generate simple statements straight from the Database Explorer. While live templates cover many cases where you need to write a simple query, context live templates take into account the context of the database explorer and the data source that you are using.

In the following animation, we use the Select first N rows from a table context live template for PostgreSQL, Microsoft SQL Server, and MySQL. Depending on a table of a data source, DataGrip generates different queries.

Context live templates

In contrast to regular live templates, context live templates use dbObjectName and dbColumns expressions for template variables and are applied to the Any SQL Statement context. For more information about template variables, see Live template variables.

Context live templates also work from the data editor. If you are working with a table and you wish to query it, you can the SQL scripts action and select the template that you need.

Context live templates also work from the data editor

View context templates

  • Open settings by pressing Control+Alt+S and navigate to Editor | Live Templates.

    Live templates, which use dbObjectName and dbColumns expressions for template variables and are applied to the Any SQL Statement context, are considered context. For example, you can view the select first N rows from a table template.

    select first N rows from a table

Apply context templates to database objects

  1. In the Database Explorer ( View | Tool Windows | Database Explorer) , right-click a database object (for example, a table or a view) and navigate to SQL Scripts.

  2. Select from the list a context template.

    Apply context templates to database objects
Last modified: 19 May 2022