Running queries¶
- Use
:[N]TDOto execute the current statement plus the nextN-1statements (split based on Tree-sitter nodes) and render table-formatted results in a split buffer. - Use
:[range]TDVto execute statements from the visual selection (split on;) and render table-formatted results in a split buffer. - Use
:[N]TDMor:[range]TDMVfor multistatement execution: submits statements as a single BTEQ job (ideal for transactions likeBEGIN TRANSACTION ... COMMIT;). - Use
:TDSessionto open a persistent BTEQ session attached to the buffer, preserving volatile tables, session query bands, and database state across commands (see Persistent sessions). - Use
:TDRerunto re-run the most recent query exactly as it was sent (bound tog.in SQL buffers and.in result buffers). - Errors are displayed with the Teradata error code and description as returned by BTEQ.
- Set
retlimit(default100) to control the maximum number of rows returned per query.
:[N]TDO " run current + next N-1 statements
:[range]TDV " run visual selection
:[N]TDM " multistatement run (single BTEQ session)
:[range]TDMV " multistatement visual selection
:TDSession " open persistent session for volatile tables
:TDRerun " re-run latest query
Multistatement queries (:TDM / :TDMV)¶
When executing dependent statements that must share a transaction or session state (such as temporary tables or explicit transaction blocks):
- Use
:TDM(normal mode with optional count[N]) or:TDMV(visual selection). - Statements are batched and executed sequentially in a single BTEQ session.
- If an error occurs, execution stops and reports the failure.
For workflows where session state must persist across separate query runs (e.g., creating volatile tables once and querying them iteratively), open a persistent session with :TDSession instead.
Re-running queries¶
Use :TDRerun to re-run the most recent query exactly as it was sent. The re-run is a new BTEQ job: it gets its own history ID and its own line in :TDJ.
A query that originally ran in a persistent session (:TDSession) is re-run within that same session, meaning it continues to access existing volatile tables. If the session has since been closed, the re-run executes as a one-shot job and displays a warning.
Keymaps¶
g.in Teradata SQL buffers..in result buffers.
(Both keymaps are configurable via rerun_keymaps.)
The two default keymaps differ intentionally: in Teradata SQL buffers, . keeps its standard Vim behavior (repeat the last change), so g. is used. In result buffers (which are nofile and read-only), plain . is free and used directly.
Window reuse¶
The refreshed grid replaces the result of the latest query wherever that result is on screen: press the key inside that result buffer, or from the Teradata buffer you ran it from, and the same window is reused.
If the result window has been closed, or you are looking at an older result, the new grid opens in its own split so nothing you are still reading is discarded.
Edit mode protection
While a result buffer is in edit mode, the re-run mapping refuses to run and asks you to save or cancel your edits first.
Output & limits¶
- Results are displayed in a table layout in a split.
retlimitlets you cap rows to control memory/latency.- When results exceed
retlimit, a warning indicates truncation. For large datasets and multi-million-row extractions, use Full exports (TPT): pressFin the result grid or run:TDExportto stream the complete data directly to a CSV file in the background.
How queries are executed via BTEQ (Under the hood)¶
Understanding how vim-teradata executes SQL under the hood helps when debugging queries, configuring connection profiles, or working with complex scripts.
1. Statement extraction & preprocessing¶
When you invoke a query command (such as :TDO):
- Tree-sitter AST extraction: The plugin asks Neovim's built-in Tree-sitter parser for the concrete syntax tree node surrounding your cursor. It identifies the exact statement boundaries (SELECT, INSERT, UPDATE, CREATE, etc.) without being fooled by semicolons enclosed in string literals ('value;with;semicolon') or SQL comments (-- comment;).
- Placeholder replacement: If you configured replacements (e.g., ['${DB_NAME}'] = 'PROD_DB'), string substitution is performed before dispatching the query.
2. The generated BTEQ wrapper script¶
Under the hood, vim-teradata constructs a BTEQ command script configured for programmatic parsing. For a standard one-shot query, the generated script looks conceptually like this:
.LOGON <tdpid>/<user>,$tdwallet(<user>)
.SET SESSION CHARSET 'UTF8'
.SET RETLIMIT 100
.SET SEPARATOR '~'
.SET TITLEDASHES OFF
.SET NULL '?'
.SET RECORDMODE OFF
<your preprocessed SQL statement>;
.LOGOFF
.QUIT
Key BTEQ directives applied:
- $tdwallet(<user>): Retrieves credentials securely from Teradata Wallet without storing plaintext passwords in Neovim or config files.
- .SET RETLIMIT: Caps the returned rows (default 100, configured via retlimit) so massive queries do not degrade Neovim's memory or rendering performance.
- .SET SEPARATOR '~': Enforces a reliable delimiter between output columns (customizable via sep).
- .SET TITLEDASHES OFF: Eliminates BTEQ header underline dashes, ensuring clean column header parsing.
- .SET NULL '?': Sets a distinct token for SQL NULL values (customizable via null_token).
3. Asynchronous execution (vim.system)¶
- The BTEQ binary (
bteq) is launched in the background using Neovim's non-blocking async process API (vim.system). - Neovim's UI never freezes; you can continue typing, editing other files, or running additional queries in parallel.
- Execution progress is tracked in real time in the Job Manager (
:TDJ).
4. One-shot vs. persistent session execution¶
- One-shot execution (default): Spawns an isolated
bteqprocess that logs on, executes the statement, and exits. Ideal for independent queries and parallel execution across multiple buffers. - Persistent sessions (
:TDSession): Maintains a single long-livedbteqprocess attached to the buffer, communicating viastdin/stdoutpipes. Boundary.REMARKmarkers delineate individual query outputs. This avoids repeated logon overhead and preserves session state, such as volatile tables (CREATE VOLATILE TABLE ...), session query bands, and database defaults (DATABASE <db>;).
5. Output parsing & table rendering¶
When BTEQ finishes:
- Standard output is parsed using the configured delimiter (sep).
- Column widths are computed dynamically to format a readable, aligned table rendered in a split buffer.
- Teradata database error messages (*** Failure 3706 ... or *** Error ...) are parsed into visible diagnostics and error banners.
- The query text, execution duration, row count, and output path are appended to your local history (:TDR).