Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is a uuid column ordered in ORDER BY?

Tags:

postgresql

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.

like image 301
Code Avatar asked Oct 15 '25 03:10

Code


1 Answers

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.

like image 128
Laurenz Albe Avatar answered Oct 17 '25 00:10

Laurenz Albe