You can execute the ALTER TABLE
statement to modify a table.
The current Hologres version allows you to execute the ALTER TABLE statement to rename a table, add columns to a table, and modify properties of a table.
Rename table
- Synopsis
ALTER TABLE table_name RENAME TO new_table_name;
- Limitation
An error is thrown if you execute
RENAME
to rename a table that does not exist or rename a table to the name of an existing table. - Examples
ALTER TABLE test RENAME TO holo_test ;
Add columns
- Synopsis
ALTER TABLE IF EXISTS table_name ADD COLUMN new_column_name data_type; ALTER TABLE IF EXISTS table_name ADD COLUMN col_add_1 data_type, ADD COLUMN col_add_2 TEXT IF NOT EXISTS col_add_2 data_type;
- Examples
ALTER TABLE IF EXISTS holo_test ADD COLUMN id int;
Alter table property
Generally, you must call the set_table_property function in the same transaction as CREATE TABLE. However, you can execute the following SQL statements independently to modify the specified properties:
call set_table_property('tbl', 'bitmap_columns', '[columnName [,...]]');
call set_table_property('tbl', 'dictionary_encoding_columns', '[columnName [,...]]');
call set_table_property('tbl', 'time_to_live_in_seconds', '<non_negative_literal>');
- To change the columns on which Hologres builds bit codes, execute the following SQL
statement:
call set_table_property('tbl', 'bitmap_columns', 'a,b');
- To change the dictionary encoding columns, execute the following SQL statement:
call set_table_property('tbl', 'dictionary_encoding_columns', 'a,b');
- To change the time to live (TTL) of data in a table, execute the following SQL statement:
call set_table_property('tbl', 'time_to_live_in_seconds', '86400');