Skip to content

Autocomplete

sql-autocomplete provides schema-aware SQL completion once you build a metadata index with :TDSync.


Metadata sync (:TDSync)

Full catalog synchronization builds or refreshes the local index of databases → tables → columns from your active connection:

:TDSync
  • Connects to Teradata using the active user connection via TPT.
  • Indexes all schemas visible to the user (filtered by filter_db if configured).
  • Typical duration: ~2 minutes for systems with millions of columns.
  • Requires read access to dbc.columnsv.
  • Writes one metadata catalog per machine (tdpid) under data_dir (stdpath('data') .. '/teradata').

Incremental sync (:TDSync add / update / delete)

Instead of running a full catalog sync whenever a table or schema changes, you can incrementally add, refresh, or remove objects on demand in seconds:

:[range]TDSync[!] add [DB.OBJ ...]
:[range]TDSync[!] update [DB.OBJ ...]
:[range]TDSync delete [DB.OBJ ...]

Subcommands

Action Description
add Fetches metadata for the given objects from DBC.ColumnsV via TPT and merges them into the local catalog.
update Fetches the given objects via TPT, merges them into the local catalog, and removes any requested objects that no longer exist on the server.
delete Removes the given objects from the local catalog directly. Synchronous and executes locally without querying the server.

Target options

You can target objects in several flexible ways:

  • Explicit object names: Pass one or more qualified objects separated by spaces or commas:

    :TDSync add PROD_DB.Orders PROD_DB.Customers
    
    Placeholders defined in replacements (such as ${DB_NAME}) are automatically expanded.

  • Wildcard whole database (DB.*): Update or delete an entire database:

    :TDSync update PROD_DB.*
    :TDSync delete STAGING_DB.*
    

  • From cursor position (no arguments): In a Teradata buffer, :TDSync add or :TDSync update without arguments inspects the Tree-sitter object_reference node under the cursor and syncs that table automatically.

  • From visual selection: Highlight SQL statements containing table references and run:

    :'<,'>TDSync add
    
    Object names are extracted directly from the selected text.


Volatile & Temporary tables

When working with session-level tables (CREATE VOLATILE TABLE or CREATE GLOBAL TEMPORARY TABLE), pass an unqualified single-part table name:

:TDSync add vt_orders
  • Session-only registry: Registered in memory for the active Neovim session (not persisted to disk).
  • Tree-sitter AST extraction (default): By default, column definitions are extracted directly from the CREATE VOLATILE TABLE or CREATE GLOBAL TEMPORARY TABLE statement found in the current buffer.
  • Server-side column resolution (!): Append ! to verify column definitions on Teradata:
    :TDSync add! vt_orders
    " or
    :TDSync! add vt_orders
    
    This runs a fast one-shot BTEQ job that creates the table with WITH NO DATA and executes HELP COLUMN vt_orders.* on the server to accurately resolve types and computed column names.
  • Removing session tables: To remove a volatile table from autocomplete:
    :TDSync delete vt_orders
    

Completion behavior

  • Scope-aware suggestions:
    • After FROM or JOIN: completes databases, then tables.
    • After <table>.: completes columns belonging to that table.
    • Teradata built-in SQL functions are always suggested.
  • Case-insensitive matching.
  • Candidate ranking and fuzzy matching are handled by your completion plugin.

Supported engines

blink.cmp

Automatically registered as a completion provider if blink.cmp is detected.

nvim-cmp

Automatically registered if nvim-cmp is detected. Simply add td_sql_completion to your sources list:

cmp.setup({
  sources = {
    { name = 'td_sql_completion' },
    -- your other sources...
  },
})

Built-in omnifunc (<C-X><C-U>)

If you do not use blink.cmp or nvim-cmp, you can invoke native Neovim completion anywhere in a Teradata buffer using insert-mode <C-X><C-U>.

Demo

Terminal