10

I want a column to have a unique value in every insertion. In SQL we can have this using autoincrement, in Clickhouse can we have this functionality using any type like auto increment or any other? I am new to Clickhouse so there may be a terminology mistake.

Bridge
  • 29,818
  • 9
  • 60
  • 82
Ankit Juneja
  • 117
  • 1
  • 1
  • 6

2 Answers2

9

There is no server-provided auto-increment in ClickHouse.

As stated by other answers, UUID's is the way to go.

Instead, use generateUUIDv4() (see documentation here)

Sample output

SELECT generateUUIDv4();

Use during insert

INSERT INTO t VALUES (generateUUIDv4(), ...);
Silas Hansen
  • 1,669
  • 2
  • 17
  • 23
7

There's nothing like auto increment in ClickHouse.

If you need unique value, use UUID. It works much better for distributed systems than just auto incremented value

So you can simply generate random Uint64 and convert it to UUID

SELECT toUUID(rand64());

With insert it would look similar to this

INSERT INTO t VALUES (toUUID(rand64()), ...);
simPod
  • 11,498
  • 17
  • 86
  • 139