qSQL · Delete · Practice Question
Delete a Column from a Table
Remove a Column from a Table
Question
Given the following table:
t:([] sym:`AAPL`MSFT`GOOG`TSLA`NVDA;
qty:100 200 150 75 300;
price:185.25 410.10 142.80 238.50 875.20)Return the table without the price column.
Solution
Method 1
delete price from tMethod 2
(enlist `price) _ tResult:
sym qty
--------
AAPL 100
MSFT 200
GOOG 150
TSLA 75
NVDA 300Explanation
The qSQL delete statement can be used to remove a column from a table:
delete price from tThis returns a new table without the price column.
The same result can be achieved using the Drop operator _:
(enlist `price) _ tHere:
enlist `pricecreates a one-item symbol list containing the column name to remove.
The _ operator removes that column from the table.
Both methods return the table with only the remaining columns:
sym qty
--------
AAPL 100
MSFT 200
GOOG 150
TSLA 75
NVDA 300The qSQL version is usually clearer, while the _ version is useful when the columns to remove are stored in a variable.