How to set default values when creating a table in Hive?
In Hive, the DEFAULT keyword can be used to assign default values to table fields. If no value is provided for a field when inserting data, the default value will be used.
Here is an example of setting default values when creating a table in Hive:
CREATE TABLE my_table (
id INT,
name STRING DEFAULT 'John',
age INT DEFAULT 18
);
In the example above, the default value of the name field is set to ‘John’ and the default value of the age field is set to 18. When inserting data, if no value is provided for the name or age field, the default values will be used. For example:
INSERT INTO my_table (id) VALUES (1);
In the example above, the “name” field will be set to ‘John’ and the “age” field will be set to 18.
Please note that setting a default value only applies when no value is provided when inserting data. If a value is provided during data insertion, that value will be used instead of the default value.