Code actions¶
Speed up Teradata SQL editing with one‑keystroke transformations provided by vim‑teradata.
Trigger
Use:TDCodeActionon the current cursor position to open the action picker. This does not override your LSP code actions; it’s a separate Teradata‑aware action set specific to this plugin.
1) Expand *¶
Turn SELECT * into an explicit column list for the target table/view. Helpful for reviews, linters, and when you’ll filter or reorder columns.
Before
SELECT *
FROM Sales.OrderItems oi;
After
SELECT
oi.OrderItemId,
oi.OrderId,
oi.ProductId,
oi.Quantity,
oi.UnitPrice
FROM Sales.OrderItems oi;
Demo
2) Auto aliases¶
Automatically insert short, readable table aliases and apply them to column references.
Before
select
ERROR_CODE
, EVENT_DESC
, EVENT_ID
from
RANDOM_DATA_LAB.T5_SYSTEMLOGS
where ERROR_CODE not in (
select
CATEGORY_LABEL
from
RANDOM_DATA_LAB.T4_INVENTORY
);
After
select
ts.ERROR_CODE
, ts.EVENT_DESC
, ts.EVENT_ID
from
RANDOM_DATA_LAB.T5_SYSTEMLOGS ts
where ts.ERROR_CODE not in (
select
ti.CATEGORY_LABEL
from
RANDOM_DATA_LAB.T4_INVENTORY ti
);
Demo
3) Extract subquery to CTE¶
Promote an inline subquery to a named CTE for clarity and reuse.
Before
select * from (select * from RANDOM_PLOP_LAB.T1_LOGISTICS)
After
with s as (
select * from RANDOM_PLOP_LAB.T1_LOGISTICS
)
select * from s
Demo
4) Generate DELETE from a SELECT¶
Turn a qualifying SELECT into a safe, key‑based DELETE. The generator keeps the FROM/JOIN/WHERE logic and wires the target table by key.
Example source SELECT
SELECT t.OrderId
FROM Sales.Orders t
WHERE t.Status = 'CANCELLED';
Generated DELETE
delete FROM Sales.Orders t
WHERE t.Status = 'CANCELLED';
Demo
Heads‑up
Always review the generatedDELETE(keys & filters) before execution.
5) Generate INSERT from a SELECT¶
Wrap a SELECT with an INSERT INTO … (columns) SELECT … scaffold. Use when materializing query results into a table.
The default picker lets you select the database of the target table for the INSERT, matching the table used in the FROM clause.
Example source SELECT
SELECT
o.ERROR_CODE
, o.EVENT_DESC
, o.EVENT_ID
FROM RANDOM_DATA_LAB.T5_SYSTEMLOGS o
QUALIFY ROW_NUMBER() OVER (PARTITION BY o.EVENT_DESC ORDER BY o.EVENT_ID DESC) = 1;
Generated INSERT
insert into RANDOM_PLOP_LAB.T5_SYSTEMLOGS (
ERROR_CODE,
EVENT_DESC,
EVENT_ID
)
select
ERROR_CODE,
EVENT_DESC,
EVENT_ID
FROM RANDOM_DATA_LAB.T5_SYSTEMLOGS o
QUALIFY ROW_NUMBER() OVER (PARTITION BY o.EVENT_DESC ORDER BY o.EVENT_ID DESC) = 1;
Demo
6) Autocomplete join condition¶
When your cursor is after ON after typing a JOIN, propose join predicates (same‑name columns) so you can insert a suggestion instead of typing it.
Before
SELECT *
FROM Sales.Orders o
JOIN Sales.OrderItems i ON |
After
SELECT *
FROM Sales.Orders o
JOIN Sales.OrderItems i ON o.OrderId = i.OrderId;
Demo
7) Alias renaming¶
Rename a table alias and update all its references within the current statement/scope.
Before
SELECT o.OrderId, o.OrderDate
FROM Sales.Orders o;
Action → rename o → ord
After
SELECT ord.OrderId, ord.OrderDate
FROM Sales.Orders ord;
Demo
Tips¶
- Combine Auto aliases → then Expand * to get clean, explicit column lists quickly.
- Use Extract subquery to CTE before sharing queries to make intent obvious.
- For Generate DELETE/INSERT, treat the result as a scaffold—review keys/columns.