Default a Column’s Value: Quick Tip

Posted October 29, 2018 by Phil Molea, Sr. Information Developer, Vertica

Rear view of two partially unrecognizable men sitting in front of a computer. One of them is pointing at a screen where are several lines of computer code.
Jim Knicely authored this tip

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

Example: dbadmin=> CREATE TABLE a (b INT, c TIMESTAMP DEFAULT sysdate); CREATE TABLE dbadmin=> INSERT INTO a (b) SELECT 1; OUTPUT -------- 1 (1 row) dbadmin=> SELECT * FROM a; b | c ---+---------------------------- 1 | 2018-10-29 03:42:33.793011 (1 row) Helpful Links:

https://www.vertica.com/docs/latest/HTML/index.htm#Authoring/SQLReferenceManual/Statements/column-constraint.htm

Have fun!