Skip to main content
MySQL stores a UUID as text or as a BINARY(16) you convert by hand. vsql_uuid adds a real uuid column type that holds 16 bytes, prints as the familiar 36-character form, and sorts by its own comparison rule. It also generates versions 1, 3, 4, 5, 6, and 7, where MySQL’s own UUID() produces version 1 only.

Install

vsql_uuid.veb is already in the server’s lib/veb/ directory if you installed VillageSQL with the install script, the Docker image, or a release tarball. Install it into the server with one statement:
Confirm it is there:
To build it yourself, follow the build instructions in the repository.

What it adds

The uuid type

Declare the column as uuid. It occupies 16 bytes and works as a primary key.

Functions

Example

Use a version 7 identifier as the primary key, so rows written later sort after rows written earlier, then read the version back:
Derive a stable identifier from a name:
The ordering above holds only across milliseconds. Version 7 puts a millisecond timestamp at the front and fills the rest randomly, with no counter, so two values generated in the same millisecond sort in a random order relative to each other. That is why the example inserts the two rows in separate statements. Use UUID_V6() when you need ordering finer than that.
A uuid column accepts a string literal, but not a string expression. So INSERT INTO orders VALUES ('550e8400-e29b-41d4-a716-446655440000', ...) works, while INSERT INTO orders VALUES (UUID(), ...) fails with ERROR 3219 (HY000): Incorrect uuid value: cannot implicitly cast string expression. Use explicit conversion for column 'id' at row 1. Generate the value with one of the functions above instead.

See also