By adding special comments to a SQL (select) statement, you can influence the way the result is displayed in SQL Workbench/J. This comments are called "annotations" and must be included in a comment preceding the statement that is executed. The comment can be a single line or multi-line SQL comment
You can change the name of the result tab associated with a statement. To give a result
set a name, use the annotation @WbResult
followed by the name that should
appear as the result's name.
The following examples executes two statements. The result for the first will be labelled "List of contacts" and the second will be labelled "List of companies":
-- @WbResult List of contacts SELECT * FROM person; /* @WbResult List of companies this will retrieve all companies from the database */ SELECT * FROM company;
The result name that is used, will be everything after the annotation's keyword until the end of the line.
For the second select (with the multi-line comment), the name of the result tab will be
List of companies
, the comment on the second line will not be considered.
If the result of a query should be displayed in an existing result tab, the annotation @WbUseTab
together with a tab name can be used. If this annotation is present and a result tab with that name already
exists, the existing result will be replaced with the new result. If no result tab with that name exists,
a new tab (with the supplied name) will be created.
![]() | |
Re-using a result tab only works if @WbUseTab with the @WbAppendResult annotation to
force re-using an existing result even though the option is turned off.
| → is enabled.
You can combine
If the following query is run for the second time, the existing data will be replaced with the newly retrieved data:
-- @WbUseTab List of contacts SELECT * FROM person;
The annotation @WbScrollTo
can be used to automatically scroll a result set after it has been retrieved
to a specific row number. The row number has to be supplied using a #
sign:
-- @WbScrollTo #100 SELECT * FROM person;
In addition to a row number, the special values end
or last
(without a #
)
are also recognized. When they are supplied, the result is automatically scrolled to the last row.
This is useful when displaying the contents of log tables.
-- @WbScrollTo end SELECT * FROM activity_log;
The annotation @WbAppendResult
can be used to always append the result of the associated query regardless of
the current setting of → .
To suppress an empty result, the annotation @WbRemoveEmpty
can be used. If a query
returns no rows and contains this annotation, no result tab will be created. No warning or message will
be shown if this happens!
To automatically refresh a result in a defined interval, the @WbRefresh
annotation
can be used. The interval is specified as a parameter to the annotation:
-- @WbRefresh 15s SELECT * FROM pg_stat_activity;
The automatic refresh can also be enabled through the context menu of the result tab.