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

OWNED BY

Enterprise only.

When a user adds a new column to a table, they automatically get all column level permissions with the GRANT option for that column. However, if the OWNED BY clause is used, the permissions instead go to the user, group, or service account named in that clause.

The OWNED BY clause cannot be omitted if the column is added by an external user, because permissions cannot be granted to them.

Examples

Add a new column called comment of 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;