How to quickly generate a SELECT statement for a table in a DataGrip?

In Microsoft SQL Server Management Studio (SSMS), you can right-click on a table and then go to Script Table as β†’ SELECT To , and then select the destination for the generated script.

Is there something similar in DataGrip, or is it possible to somehow create a custom structure?

The reason I find this useful is because I often find that I work with a table with a lot of columns, and I want to select all but a few of them. Therefore, it’s easier to just generate a SELECT statement with all explicitly specified columns so that I can just go through and delete the ones that I don’t need.

My current workaround in DataGrip is to right-click on a table, then select Copy DDL . This generates a CREATE TABLE statement, which lists all columns, but also includes column definitions. Therefore, I have to make a regular expression, replace or run a macro to get rid of additional information, which is a kind of pain. Does anyone have a better solution?

+15
source share
2 answers

In DataGrip, like other built-in IDEs, everything is related to editing the source code. Thus, this can be achieved as follows:

  • Open console
  • Start typing sel , you will get a completion popup (if not, press Ctrl+Space )
  • Select sel here, which is a live-template for the select statement
  • A query statement is selected that queries the table name and column list. enter image description here
  • Select the desired table after completion, specify * as a list of columns
  • Then press Alt+Enter on the asterisk and select Expand column list enter image description here

I suggest you browse https://www.jetbrains.com/datagrip/features/

+26
source

In DataGrip 2018.3 you can use postfix completion. This is a flexible way to get the necessary requests.

Try to dial

 SELECT %table_name%.from SELECT %table_name%.afrom SELECT %table_name%.join 

And it will be expanded to the necessary requests. In the case of from completion, you can write columns.

This makes writing SQL more logical: first you specify the table, and then the columns.

Watch GIF: enter image description here

0
source

Source: https://habr.com/ru/post/1013837/


All Articles