I am going to create some table at Vertica Database on which i have to give Global Unique Identifier to identify each row uniquely. Please suggest how to do it?
Globally Unique Identifier in Vertica
1.2k Views Asked by San At
2
There are 2 best solutions below
0
On
A named sequence is what you are looking for. You can use the same sequence for multiple tables:
-- 2 tables...
CREATE TABLE tst (id INT, value varchar(10));
CREATE TABLE tst2 (id INT, value varchar(10));
-- 1 sequence...
CREATE SEQUENCE tst_seq;
-- ... said sequence is used by both tables
ALTER TABLE tst ALTER COLUMN id set default NEXTVAL('tst_seq');
ALTER TABLE tst2 ALTER COLUMN id set default NEXTVAL('tst_seq');
-- testing...
INSERT INTO tst (value) VALUES ('tst');
INSERT INTO tst2 (value) VALUES ('tst2');
-- success!
=> SELECT * FROM tst;
id | value
----+---------
1 | tst
(1 row)
=> SELECT * FROM tst2;
id | value
----+----------
2 | tst2
(1 row)
Then NEXTVAL('named_sequence'), here used during table creation, is the equivalent of NEWID() you are looking for.
Please refer to the documentation:
Types of Incrementing Value Objects