Using Code Snippets

To facilitate working with the application, Aginity Workbench supports code snippets—short, and often reusable strings that can be expanded to create a statement.

For example, a default "sf" snippet can be expanded into a SELECT statement with a LIMIT clause. If you type "sf" in the Query Analyzer, and then press ALT+C, the ‘"sf" will be replaced with the actual predefined SELECT statement.

To view and edit default code snippets, or to add a new one, select Tools > Options > Code snippets. Code snippets are defined separately for each database. To edit a snippet, double-click it, or click Modify. The Code Snippet Properties window will be displayed. Make the appropriate changes, and then click OK.

The pointer will remain in the position in which you will leave it in the box, until you click OK when using the Add New or Modify function.

Code snippets are defined separately for each database.

Adding a New Code Snippet

To add a new code snippet:

  1. On the Tools menu, select Options.
  2. In the Application Options dialog box, click the Code Snippets node.
  3. Click Add New.
  4. In the Code Snippet Properties dialog box, enter a code to use for the snippet in the Snippet Code field. The code must consist of alphanumeric characters, and it can contain underscores.
  5. In the Snippet Text field, enter a valid statement for the snippet.
  6. When you are finished, click OK.
  7. When you are returned to the Application Options dialog box, click OK.

Editing Existing Code Snippets

To edit an existing code snippet:

  1. On the Tools menu, select Options.
  2. In the Application Options dialog box, click the Code Snippets node.
  3. Select the code snippet and click Modify.
  4. In the Code Snippet Properties dialog box, edit the snippet.
  5. When you are finished, click OK.
  6. When you are returned to the Application Options dialog box, click OK.

Deleting Code Snippets

To delete a code snippet:

  1. On the Tools menu, select Options.
  2. In the Application Options dialog box, click the Code Snippets node.
  3. Click Delete. When prompted, confirm you want to delete the snippet.
  4. When you are finished, click OK.
  5. When you are returned to the Application Options dialog box, click OK.

Snippet Shortcuts

The following shortcuts can be used to add, delete, or modify a snippet in the Code Snippet screen of the Application Options dialog box:

Using Code Snippets

To insert a code snippet in the Query Analyzer window:

  1. Type the code for the snippet.
  2. Select the code and press Alt+C.

The selected text will be replaced by the snippet value.

Exporting Code Snippets

There are times when you may find useful to export the code snippets that you created in Workbench to a file. For example, you want to transfer the Workbench snippets on your work computer to your home computer, or you want to save them to a file so that other people can import them from there and use them in their Workbench.

To export the code snippets to a file:

  1. On the Tools menu, click Options.
  2. In the Application Options dialog box, in the left pane, click Code snippets.
  3. In the Code Snippets section, click Export.
  4. In the Export Code Snippets dialog box, move the snippets that you want to export to the Code Snippets to Export area by using the arrow buttons.
  5. Click OK, type a name for the snippets (.wbsnippets) file, and save it to an appropriate location.

Importing Code Snippets

You can import the code snippets from a previously saved file into your Workbench.

To import code snippets:

  1. In the Application Options dialog box, in the left pane, click Code snippets.
  2. In the Code Snippets section, click Import.
  3. Browse to and open the code snippets (.wbsnippets) file.
  4. In the Import Code Snippets dialog box (shown below), next to Quick filters, click the appropriate filter buttons for the types of code snippets that you want to import:
    • Unchanged - Code snippets that are exactly the same as existing code snippets in your Workbench.

      Most times, you don't need to select Unchanged. You can select this filter if you want to overwrite existing code snippets.

    • New - Code snippets that don't exist in Workbench yet.
    • Modified - Code snippets that are similar to existing code snippets in Workbench but contain some differences in their code. After import, the existing snippets will be overwritten with the imported snippets.

    The list of the code snippets from the file is filtered according to the filters you have selected, as shown below. When you select a Modified snippet row in the table, the Diff box displays the differences in the code between the snippet being imported (New) and the existing snippet (Old).

  5. In the Import column, select the check box next to each snippet you want to import or click Check All and click OK.
  6. Click OK.

    The imported code snippets become available in Workbench. You can view them in the list in the Code Snippets section of the Application Options dialog box.


Aginity Workbench for Greenplum * Topic last updated August 30, 2018