ALTER TABLE ADD COLUMN

Adds a new column of a specified type to an existing table.

The new column is not back-populated even if the table contains data. While a single column is added atomically, adding multiple columns is not an atomic operation. QuestDB will stop adding the remaining columns on the list on the first failure. It is therefore possible to add some columns and not others.

caution
  • New column names may only consist of letters, numbers and underscores _

  • Adding a new column does not lock the table for reading and does not wait on any reads to finish.

Syntax#

Flow chart showing the syntax of the ALTER TABLE keyword Flow chart showing the syntax of ALTER TABLE with ADD COLUMN keyword

Examples#

Add a new column called comment of type STRING type to the table ratings

New column
ALTER TABLE ratings ADD COLUMN comment STRING;

When adding a column of Symbol type, optional keywords may be passed which are unique to this type. These keywords are described in the Symbol type section of the CREATE TABLE documentation.

The following example shows how to add a new SYMBOL column with NOCACHE and INDEX keywords:

New symbol column
ALTER TABLE ratings ADD COLUMN comment SYMBOL NOCACHE INDEX;