Please take this survey to help us learn more about how you use third party tools. Your input is greatly appreciated!

Derive a Table Column’s Default Value from another Column

You can specify a table column's default value using a DEFAULT expression. Vertica evaluates the DEFAULT expression and sets the column on load operations, if the operation omits a value for the column.

That DEFAULT expression can be derived from another column in the same table!


dbadmin=> CREATE TABLE A (b INT, c INT DEFAULT b * 2);

dbadmin=> INSERT INTO A (b) SELECT 1;
(1 row)

dbadmin=> INSERT INTO A (b) SELECT 2;
(1 row)

dbadmin=> SELECT * FROM a;
b | c
1 | 2
2 | 4
(2 rows)

Helpful Link:

Have fun!

Sign In or Register to comment.

Can't find what you're looking for? Search the Vertica Documentation, Knowledge Base, or Blog for more information.