Code refactoring
Refactoring is a process of improving your source code without creating a new functionality. Refactoring helps you keep your code solid and easy to maintain.
Place the caret at the object that you want to rename.
In the object's content menu, select Rename ShiftF6. If you edit an argument in the function, you can start typing a new name inline, or press ShiftF6 twice to invoke the Rename dialog.
If you rename the element inline, you can click icons near the element, and select whether you want to rename it in comments and strings or all the text occurrences.
In the Rename dialog, type a new name for the object.
Review changes and click Refactor. To search for usages of the object name, click Preview.
tip
To rename a database object without code refactoring, clear the Comments and strings and Text occurrences checkboxes in settings.
In the editor start renaming a column, a variable, or any other code element. DataGrip will display in the gutter.
Click the gutter icon or press AltEnter and apply a suggestion.
DataGrip renames the code element and updates its usages accordingly.
Place the caret at a variable in the function.
Navigate to Refactor | Introduce Variable (CtrlAlt0V).
Select a part of the expression that you want to extract and press Enter.
CTE is a temporary result set that you can use within another SELECT
, INSERT
, UPDATE
, or DELETE
statements. In DataGrip you can extract a subquery and convert it to CTE.
Right-click the subquery that you want to convert and select Refactor | Subquery as CTE.
Select a query that you want to extract as a table function.
Right-click a selection and select Refactor | Extract Routine. Alternatively, press CtrlAlt0M.
In the Name field, type the routine's name.
In the Parameters field, select or clear checkboxes for parameters that you want to use.
For some refactorings, DataGrip lets you preview the changes before applying them.
Click Preview in the Refactoring Preview dialog to see potential changes (the list of usages where the refactoring will be performed).
In the Find tool window that opens, check the changes that are going to be made. You can exclude Delete or remove Ctrl0X changes that you consider unnecessary.
Click Do Refactor to proceed with the changes.
Thanks for your feedback!