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

Why AUTO_INCREMENT in Vertica doesn't work correctly and return something wrong?

edited May 18 in General Discussion

Hi guys,

Currently I have a task which needs use auto_increment and I apply this for my task like the code below:
CREATE TABLE ip_data_newpartition (
ID IDENTITY(1,1),
"key" VARCHAR(512),
"ip" VARCHAR(512),
"_sys_updated_at" TIMESTAMP ENCODING RLE
);
I have followed this document
but it doesn't make sense. When I select the table ip_data_newpartition, 84 first records are numbered correctly but after the record with ID = 84, the table has some problem. It starts from the ID = '250001' instead of starts from the ID = 85. Moreover, after the record with ID = 250074, the table starts from the ID = 500001 instead of using the ID = 250075. I still don't understand why this problem can happen and how can I fix this? I'm sure that all the records are unique.

Please help me to fix this. Thank you so much for your help.
Hope your guys have a good day.

Answers

  • Bryan_HBryan_H Administrator
    edited May 18

    Each node creates a default cache of unique values so it's possible that an INSERT on node2 will return a value from a different unique range than node1. To avoid this, disable the sequence cache by setting the third optional parameter of IDENTITY to 0:
    CREATE TABLE ip_data_newpartition (
    ID IDENTITY(1,1,0),
    "key" VARCHAR(512),
    "ip" VARCHAR(512),
    "_sys_updated_at" TIMESTAMP ENCODING RLE
    );

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file

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