Change UUID type default output representation

From: Randall Lucas <rlucas(at)tercent(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Change UUID type default output representation
Date: 2015-05-28 21:35:57
Message-ID: CAHL9ZMzngzyjrdO_jDEnXvDuov1D9U=w-Yx-NmHEz+F1e1trqw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have been using UUIDs for PKs to allow me the flexibility of
generating PKs within PostgreSQL or at the application code level.

However, I have been storing them as CHAR(32) in the hex string
representation (no dashes) in order to simplify comparisons and
manipulations at a very practical level.

(For example, in my terminal, the dashes become "word boundaries" for
cut-and-paste operations, so that dealing with
"5371ab73-3421-4db2-95ce-441fb8621f92" is much more fraught than
dealing with its dashless form, "5371ab7334214db2-95ce441fb8621f92".)

I am now running into some issues with object sizes (link tables and
indices mainly) which I would think to ameliorate at least temporarily
by switching to the UUID type (128-bit binary storage instead of 32
bytes). PostgreSQL's UUID type is very forgiving about accepting
input and will take the dashless form flawlessly.

Changing the UUID type's output representation to the dashless form,
however, has me stumped. Any ideas? I looked at creating a domain or
a user-specified type, but I don't see how I can change what is output
by default in psql (and what is given in "string" format to my ORM
layer).

(Warning, pgsql-hackers territory below.)

Current best idea:

In src/backend/utils/adt/uuid.c at line 25, uuid_out seems to be hard-coded.

Can I compile my own version of uuid_out and update the system
catalogs, or create a "uuid_dashless" type that uses my own custom
uuid_dashless.c that's hacked to remove dashes? Will I break
everything if I try this?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2015-05-28 22:21:39 Re: [HACKERS] Re: 9.4.1 -> 9.4.2 problem: could not access status of transaction 1
Previous Message Joshua D. Drake 2015-05-28 20:06:46 Re: Re: [GENERAL] 9.4.1 -> 9.4.2 problem: could not access status of transaction 1