Code
Code

Reputation: 6251

How is a uuid column ordered in ORDER BY?

How is a uuid column ordered when used with ORDER BY? Is it based on its string representation? I can't seem to find any documentation regarding this.

Upvotes: 4

Views: 3957

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 247535

This function compares UUIDs in PostgreSQL:

/* internal uuid compare function */
static int
uuid_internal_cmp(const pg_uuid_t *arg1, const pg_uuid_t *arg2)
{
    return memcmp(arg1->data, arg2->data, UUID_LEN);
}

So UUIDs are compared lexically byte for byte using the binary values.

Upvotes: 9

Related Questions