Skip to content

Editing Results

Results from query execution (:TDO / :TDV) can be edited directly inside Neovim and saved back to Teradata as UPDATE statements.

This feature provides an interactive, keyboard-driven way to edit result sets without manually writing UPDATE queries while protecting against syntax or alignment corruption.

Terminal
 

Interactive Controls

When viewing query results in the split window, use the following keymaps:

Keymap Action Description
<E> Toggle Edit Mode Switches the resultset buffer between view mode and edit mode.
<CR> Edit Cell Prompts for a new value for the cell under the cursor.
<X> Set to NULL Sets the selected cell value to NULL.
<S> Save Changes Generates and executes UPDATE statements for all pending changes.
<C> Cancel Edits Discards all pending changes and restores original values.
. Re-run Query Re-runs the latest query (view mode; prompts to save or cancel first if in edit mode).
<F> Full Export (TPT) Exports the full query result to a CSV file in the background via TPT (view mode; see Full exports (TPT)).

How It Works

  1. Safe Prompt-Based Editing:
    Values are modified through an interactive Neovim prompt rather than direct buffer typing. The results buffer remains read-only and is redrawn from the data model after each change. This ensures column alignment is preserved and values containing spaces, pipes (|), or newlines are handled safely.

  2. Visual Feedback:
    Changed cells are highlighted in the grid, and a hint line displays the count of pending edits.

  3. Batched Execution & Staged Preview:
    You can change multiple cells across multiple rows before saving. When preview_updates is enabled (true by default), pressing <S> opens the generated UPDATE statements in a scratch buffer for review. Nothing is sent to BTEQ until you press <CR> in that buffer.

  4. Handling NULL Values:
    Pressing <X> or typing the configured null_token (default "NULL") sets the cell to SQL NULL. In generated queries, this becomes SET col = NULL and WHERE col IS NULL.


Configuration Options

In-grid editing can be configured via require('vim-teradata').setup({ ... }):

  • edit_enabled: Enable or disable editing (true by default).
  • preview_updates: Review generated SQL in a scratch buffer before running (true by default).
  • null_token: String token representing SQL NULL ("NULL" by default).
  • edit_keymaps: Customize result buffer keys (default { toggle = "E", save = "S", cancel = "C" }).

Editable vs. Read-Only Columns

The plugin uses Tree-sitter AST analysis to determine which columns in a result set map to actual database columns:

  • Editable Columns: Direct table column references, such as column_name, table.column_name, table.column_name AS alias, or table.column_name alias.
  • Read-Only Columns: Expressions, function calls, literals, and wildcard selects (*). These cells appear dimmed and cannot be edited.

Update Strategies

Single-Table Queries

For single-table SELECT queries, the generated WHERE clause matches every editable column against its original value ("matchall" strategy). Original NULL values are translated to IS NULL.

Affected Rows

Because updating is value-matched rather than primary-key matched, multiple identical rows may be updated. The exact number of rows changed is always reported after saving.

Join Queries

For queries with JOIN statements:

  • Edited columns are traced back to their source table using the Tree-sitter syntax tree.
  • You will be prompted to select which columns form the WHERE clause once for each table containing edits.
  • Your column selection for the WHERE clause is remembered for the duration of the buffer session.

Persistent Sessions & Volatile Tables

Saving edits (<S>) on results produced in a persistent session (:TDSession) routes the generated UPDATE statements directly through that same session. This makes it possible to edit and update volatile tables interactively. If the persistent session has been closed, the statements run in a standard one-shot job (which will fail for volatile tables).

Sandboxed "What-If" Editing with Materialized Tables

If you want to edit cells in queries that would otherwise be non-editable (such as queries with joins, expressions, or wildcard selects) or experiment with values safely without risking production data:

  1. Materialize the answerset into a session volatile table with :TDMaterialize (requires an active :TDSession).
  2. Set the edit destination to the volatile table by running :TDEditTarget volatile (or configuring virtual.edit_target = "volatile").
  3. Press <E> to enter volatile edit mode (-- EDIT MODE (VT <name>) --). In this mode, every column is editable.
  4. Press <S> to stage and save edits. The generated UPDATE statements are dispatched strictly against the session volatile table, leaving underlying production tables completely untouched. Re-run gD to compute updated aggregates over your modified dataset. See Virtual answersets: Safe What-If In-Grid Editing.

Non-Editable Queries

Editing is disabled for complex or non-deterministic queries, including:

  • SELECT * (wildcard queries)
  • Queries using DISTINCT
  • Aggregated queries with GROUP BY or HAVING
  • Set operations (UNION, INTERSECT, EXCEPT)
  • CTEs (WITH clauses) and derived tables / subqueries
  • Multistatement execution results (:TDM / :TDMV)
  • EXPLAIN and SHOW statements