Re: How to migrate column type from uuid to serial - Mailing list pgsql-general

From Francisco Olarte
Subject Re: How to migrate column type from uuid to serial
Date
Msg-id CA+bJJbyKb+dKSJfp7TCqHCGNTER3PEhnice4s4sF6nFTCvausA@mail.gmail.com
Whole thread Raw
In response to How to migrate column type from uuid to serial  (Hemil Ruparel <hemilruparel2002@gmail.com>)
Responses Re: How to migrate column type from uuid to serial  (Hemil Ruparel <hemilruparel2002@gmail.com>)
List pgsql-general
Hemil:

On Wed, Oct 7, 2020 at 2:49 PM Hemil Ruparel <hemilruparel2002@gmail.com> wrote:
> I was integrating a payment gateway for my app when I noticed its maximum length of customer id string is 32. SIze of
UUIDis 36 (32 characters and 4 dashes). So I want to change the type of customer id to serial. The problem is by now,
thecolumn is being used at many places. How to migrate the column to serial without dropping the data? 

An uuid is just a 128 bit number, as noted by many. Your problem is
the default encoding is 32 hex digits plus 4 hyphens. If your payment
gateway uses a 32 CHARs string  ( "maximum length of customer id
string is 32" ) you can just use other encodings. Passing to integer
and using decimal wont cut it ( you'll need 39 digits ), but using
just hex (without hyphens) will drop the string representation to 32
characters ( you can encode with a subst and postgres accepts it
without hyphens ).

If you want to buy a little more space for your own purposes you can
even fit 128 bits in 22 base64 chars with a couple pairs of bits to
spare, and IIRC you can do it with a creative decode/encode step after
killing the dashes.

And if your payment gateway uses unicode codepoints instead of ASCII
chars as units you could probably use more creative encodings ;-) ,
but probably using  a "drop the dashes" subst in the interface will be
your simpler option.

Francisco Olarte.



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: What version specification used by PG community developers?
Next
From: Nick Aldwin
Date:
Subject: Missing libpq-dev version in buster-pgdg?