Running SQL queries
SQL is a standardized language for defining and manipulating data in a relational database. You can use the Query workspace interface in IBM® watsonx.data to run SQL queries and scripts against your data.
The Query workspace has the following components:
-
Engine: To select an engine and view the associated catalogs.
-
Filter for tables: To search the tables and columns.
-
Worksheet: To write SQL queries.
-
Saved worksheets: To view the saved queries.
-
Sample worksheets: To run predefined sample queries to analyze the performance between different engines on the same data set.
The Query workspace page provides basic options to undo, redo, cut, copy, paste, save, clear, and delete.
Format selection option is enabled only when an SQL statement in a query worksheet is selected. The Format worksheet option formats all the content in the worksheet. Comment selection is used to explain sections of SQL statements.
The Delete option is enabled only after an SQL query is saved.
To run the SQL queries, do the following steps:
-
Log in to the watsonx.data console.
-
From the navigation menu, select SQL. The Query workspace page opens.
-
Select an engine from the Engine drop-down.
-
Select the catalog, schema, table, or column in which you want to run the query.
-
Click the overflow menu and select the required query.
- For a catalog and schema, you can run the Generate Path query.
- For a table, you can run the Generate path, Generate SELECT, Generate ALTER, and Generate DROP query.
- For a column, you can run the Generate path, Generate SELECT, and Generate DROP query.
-
Select the Catalog and corresponding Schema from the drop-down on top of the worksheet to run queries for all tables within the schema without having to specify the path (
<catalog>.<schema>
) for every queries. -
Click the Save icon to save the query. A Save query confirmation dialog appears.
-
Click Save.
-
Click the Run button to run the query. Using Run to cursor or Run from cursor, you can run queries from or until your cursor position.
-
Select Result set or Details tab to view the results. You can export the result as a csv file using Export to CSV icon.
-
Click Saved queries to view the saved queries.
-
Click Explain to view the logical or distributed plan of execution for a specified SQL query.