COMMANDHISTORY Command | Basic Teradata Query - COMMANDHISTORY (CH) - Basic Teradata Query

Basic Teradata® Query Reference - 20.00

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
Lake
VMware
Product
Basic Teradata Query
Release Number
20.00
Published
October 2023
ft:locale
en-US
ft:lastEdition
2025-04-02
dita:mapPath
gxl1691484661681.ditamap
dita:ditavalPath
obe1474387269547.ditaval
dita:id
psp1479308573013
Product Category
Teradata Tools and Utilities

Purpose

This command helps the interactive user to display a numbered list, re-submit an item from the list, and manage the list; of previously entered BTEQ commands and SQL requests, within the same invocation.

Syntax

COMMANDHISTORY
Shorthand Syntax (Interactive Mode Only)
Command Shorthand
COMMANDHISTORY CH
Option Shorthand Option Shorthand Option Shorthand Option Shorthand
CLEAR C DISPLAY D TOP T ITEM I
RESET RS SIZE S TRIM T SUBMIT S

where the following is true:

no option
When no option is provided, displays up to 20 latest items from the list. The default display count can be changed using COMMANDHISTORY SET DISPLAY option.
CLEAR
Clears all items from the list. Item number is reset to 0, and the next entry will be stored as item #1.
DISPLAY
When no number is provided, displays up to 20 latest items from the list. The default display count can be changed using COMMANDHISTORY SET DISPLAY option.
When a number is provided, displays up to n latest items from the list. The value of n can range from 1 to 500.
When a number is provided, accepts an optional keyword TOP following it, which displays up to n top items from the list.
When ITEM keyword is used with just one number n1, displays the n1-th item, if that item exists in the list. The value of n1 can range from 1 to 4294967295.
When ITEM keyword is used with a range n1 - n2, displays the items n1 through n2, if they exist in the list. The values of n1 and n2 can range from 1 to 4294967295.
RESET
Resets the COMMANDHISTORY controls back to their original default values:
  • SIZE: 200
  • DISPLAY: 20
  • TRIM: 0
SET
  • SIZE n: Sets the maximum size the list can grow up to, after which every new command/request will lead to removal of one oldest item. The default value is set to 200 at invocation time. The value of n can range from 1 to 500.
  • DISPLAY n: Sets the default number of items to display when COMMANDHISTORY is used by itself, or COMMANDHISTORY DISPLAY is used without a number. The default value is set to 20 at invocation time. The value of n can range from 1 to 500.
  • TRIM n: Sets the default number of lines after which, the display of request text from a history item that spans multiple lines, will be trimmed. The default is set to 0, meaning no trimming. The value of n can range from 0 to 4294967295.
SUBMIT n
Submits the request text stored in the n-th item if the item exists in the list. The value of n can range from 1 to 4294967295.

Usage Notes

Users are encouraged to use the shorthand syntax CH for the COMMANDHISTORY command as well as its options.

This command is available on all supported platforms starting with BTEQ 20.00.00.07.

When running in interactive mode, BTEQ will maintain a list of all entered commands and SQL requests as history items. Any new item gets added at the end of the list, and if the list is full, the oldest item gets deleted from the beginning.

Every entry in the list is assigned an item number, which persists unless the history is cleared. This enables a command to be re-submitted using its persisting item number, as long as that item is available in the list.

An item also contains metadata about it being a BTEQ command or a SQL request, which is indicated when the list is displayed.

For example, for the following set of commands and requests entered in interactive mode:

.LOGON tdpid/username (password entered in interactive masked mode)
.REMARK 'A single-line BTEQ command'
SELECT /* A multi-line SQL request */
* FROM
dbc.dbcinfo
WHERE
InfoKey = 'Release';
SELECT /* A single-line SQL request */ date;

Following is the output of the COMMANDHISTORY command:

BTEQ -- Enter your SQL request or BTEQ command:
.COMMANDHISTORY

.COMMANDHISTORY

 -- Item# 1, Type# Command
.LOGON tdpid/username
 -- Item# 2, Type# Command
.REMARK 'A single-line BTEQ command'
 -- Item# 3, Type# Request
SELECT /* A multi-line SQL request */
* FROM
dbc.dbcinfo
WHERE
InfoKey = 'Release';
 -- Item# 4, Type# Request
SELECT /* A single-line SQL request */ date;

 BTEQ -- Enter your SQL request or BTEQ command:

The usage of COMMANDHISTORY command is not stored as a history item.

The COMMANDHISTORY command cannot follow any other command within the same instruction. When used, it must be the only command in the instruction.

If a shorthand syntax is used in the input, its expanded form gets stored as the corresponding history item.

The WIDTH setting affects the display of request text in the history items.

A request text submitted via COMMANDHISTORY SUBMIT n, gets added as a new history item.

The COMMANDHISTORY command is valid in an SQL macro.

The DEFAULTS command does not affect the COMMANDHISTORY controls. They can be managed using COMMANDHISTORY SET option.

When TRIM is set to a non-0 value, the output of COMMANDHISTORY DISPLAY will indicate that trimming has occurred for those items whose request text spans more than allowed number of lines. However, when using COMMANDHISTORY DISPLAY ITEM n option to display a specific item, that item is displayed without trimming its request text, irrespective of TRIM value.

For example, the following commands are entered after the previous input:

.COMMANDHISTORY SET TRIM = 2
.COMMANDHISTORY
.COMMANDHISTORY DISPLAY 3

As a result, the following is the output.

Observe that the item#3 is trimmed when displayed collectively but is not when displayed specifically, and the usage of COMMANDHISTORY did not get added to history.
BTEQ -- Enter your SQL request or BTEQ command:
.COMMANDHISTORY SET TRIM = 2

.COMMANDHISTORY SET TRIM = 2
 *** History item's TRIM limit set to 2 line(s).
 BTEQ -- Enter your SQL request or BTEQ command:
.COMMANDHISTORY

.COMMANDHISTORY

 -- Item# 1, Type# Command
.LOGON tdpid/username
 -- Item# 2, Type# Command
.REMARK 'A single-line BTEQ command'
 -- Item# 3, Type# Request
SELECT /* A multi-line SQL request */
* FROM
... (trimmed)
 -- Item# 4, Type# Request
SELECT /* A single-line SQL request */ date;

 BTEQ -- Enter your SQL request or BTEQ command:
.COMMANDHISTORY DISPLAY ITEM 3

.COMMANDHISTORY DISPLAY ITEM 3

 -- Item# 3, Type# Request
SELECT /* A multi-line SQL request */
* FROM
dbc.dbcinfo
WHERE
InfoKey = 'Release';

 BTEQ -- Enter your SQL request or BTEQ command:

SHOW CONTROLS COMMANDHISTORY indicates the current settings (maximum list size, default display and trim values) that are in effect, as well as the number of history items currently stored in the list.

For example, the following commands are entered after the previous input:

.SHOW CONTROLS COMMANDHISTORY

As a result, the following is the output.

 BTEQ -- Enter your SQL request or BTEQ command:
.SHOW CONTROLS COMMANDHISTORY

.SHOW CONTROLS COMMANDHISTORY

 COMMANDHISTORY MAXSIZE = 200
 COMMANDHISTORY ITEMS   = 4
 COMMANDHISTORY DISPLAY = 20
 COMMANDHISTORY TRIM    = 2

 BTEQ -- Enter your SQL request or BTEQ command: