2. Alter table#
2.1. Synopsis#
ALTER TABLE { <entries> | <find_expression> } [, ... ] ADD
{ <column_name> <data_type> }
[, ... ]
ALTER TABLE { <entries> | <find_expression> } [, ... ] RENAME
{ <current_column_name> TO <new_column_name> }
[, ... ]
ALTER TABLE { <entries> | <find_expression> } [, ... ] DROP COLUMN
{ <column_name> }
[, ... ]
find_expression ::=
FIND ( { <tag_expression> | NOT <tag_expression> } [ AND ... ] )
tag_expression ::=
TAG = 'tag_name'
2.2. Description#
ALTER TABLE will modify one or more tables in a QuasarDB cluster by adding, renaming or dropping columns with the specified schema. The statement is transactional.
2.3. Parameters#
table_nameThe name of the table to be modified. Can be alphanumeric, but is not allowed to start with a number.
find_expressionWhen your tables are tagged, you can use inline key/value lookups to perform your query over multiple tables. To match all tables that have the tag “stocks”, you can use
FIND(tag='stocks' AND type=ts).column_name,current_column_name,new_column_nameThe name of a column to be added, renamed or dropped. Can be alphanumeric, but is not allowed to start with a number.
data_typeThe data type to be associated with the column. Can be any of
INT64,DOUBLE,BLOB,TIMESTAMP,STRINGorSYMBOL.
2.4. Examples#
Add a single column to an existing table:
ALTER TABLE example ADD my_int INT64
Add multiple columns to an existing table:
ALTER TABLE example ADD my_int INT64, my_double DOUBLE, my_blob BLOB, my_ts TIMESTAMP, my_symbol SYMBOL(my_symtable)
Rename a single column of an existing table:
ALTER TABLE example RENAME my_int TO my_new_int
Rename multiple columns of an existing table:
ALTER TABLE example RENAME my_int TO my_new_int, my_double TO my_new_double
Swap names of columns in an existing table:
ALTER TABLE example RENAME column_a TO column_b, column_b TO column_a
Drop a single column from an existing table:
ALTER TABLE example DROP COLUMN my_column
Drop multiple columns from an existing table:
ALTER TABLE example DROP COLUMN column_a, column_b, column_c