This is my series of articles covering short “today I learned” topics as I work with CockroachDB. Read the previous installments:

Volume 1
Volume 2
Volume 3
Volume 4
Volume 5
Volume 6
Volume 7
Volume 8
Volume 9


Topic 1: Generating ULID strings in CockroachDB
Topic 2: Enable CLI tab completion for column names
Topic 3: Using Postico with CockroachDB Serverless
Topic 4: Nuances with DISCARD ALL
Topic 5: Npgsql and follower reads
Bonus Topic: Npgsql and pgpass

Topic 1: Generating ULID Strings in CockroachDB

CockroachDB adopted ULID several releases ago as yet another version of UUID type. There is no explicit ULID type in CockroachDB. There are functions available to generate ULID in UUID format. So in case you need to generate lexicographically sortable IDs, you can use the built-in gen_random_ulid() function. Also, there are several conversion functions to convert from ULID to UUID; i.e., ulid_to_uuid and vice versa, uuid_to_ulid. One point of friction in CockroachDB is where one needs to generate an actual ULID string and not a UUID-formatted ULID. This may or may not be obvious. Let’s take a look:

Leave a Reply

Your email address will not be published. Required fields are marked *

Generated by Feedzy