UUID and TIMEUUID

Synopsis

UUID data type is used to specify columns for data of universally unique ids. TIMEUUID is a universal unique identifier variant that includes time information.

Data typeDescription
UUIDUUID (all versions)
TIMEUUIDUUID (version 1)

Syntax

  1. type_specification ::= { UUID | TIMEUUID }
  2. uuid_literal ::= 4hex_block 4hex_block '-' 4hex_block '-' 4hex_block '-' 4hex_block '-' 4hex_block 4hex_block 4hex_block
  3. 4hex_block ::= hex_digit hex_digit hex_digit hex_digit

Where

  • hex_digit is a hexadecimal digit ([0-9a-fA-F]).

Semantics

  • Columns of type UUID or TIMEUUID can be part of the PRIMARY KEY.
  • Implicitly, values of type UUID and TIMEUUID data types are neither convertible nor comparable to other data types.
  • TIMEUUIDs are version 1 UUIDs: they include the date and time of their generation and a spatially unique node identifier.
  • Comparison of TIMEUUID values first compares the time component and then (if time is equal) the node identifier.

Examples

  1. cqlsh:example> CREATE TABLE devices(id UUID PRIMARY KEY, ordered_id TIMEUUID);
  1. cqlsh:example> INSERT INTO devices (id, ordered_id)
  2. VALUES (123e4567-e89b-12d3-a456-426655440000, 123e4567-e89b-12d3-a456-426655440000);
  1. cqlsh:example> INSERT INTO devices (id, ordered_id)
  2. VALUES (123e4567-e89b-42d3-a456-426655440000, 123e4567-e89b-12d3-a456-426655440000);
  1. cqlsh:example> UPDATE devices SET ordered_id = 00000000-0000-1000-0000-000000000000
  2. WHERE id = 123e4567-e89b-42d3-a456-426655440000;
  1. cqlsh:example> SELECT * FROM devices;
  1. id | ordered_id
  2. --------------------------------------+--------------------------------------
  3. 123e4567-e89b-12d3-a456-426655440000 | 123e4567-e89b-12d3-a456-426655440000
  4. 123e4567-e89b-42d3-a456-426655440000 | 00000000-0000-1000-0000-000000000000

See also