Re: How to migrate column type from uuid to serial

From: Hemil Ruparel <hemilruparel2002(at)gmail(dot)com>
To: Francisco Olarte <folarte(at)peoplecall(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: How to migrate column type from uuid to serial
Date: 2020-10-08 04:14:04
Message-ID: CANW1aT98ArvKYjJZng1MvDt4jjg7CT5CaQmHH+Hr16CtMM151Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I was thinking UUID was not a very good choice for id. Serial would be a
better one because I don't have a billion customers. It is more like a
thousand. So when I saw the customer ID of the payment gateway cannot
accept more than 32 characters, I thought UUID is overkill. So I want to
migrate to using a serial int instead as the primary key.,

On Wed, Oct 7, 2020 at 10:48 PM Francisco Olarte <folarte(at)peoplecall(dot)com>
wrote:

> Hemil:
>
> On Wed, Oct 7, 2020 at 2:49 PM Hemil Ruparel <hemilruparel2002(at)gmail(dot)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 UUID is 36 (32
> characters and 4 dashes). So I want to change the type of customer id to
> serial. The problem is by now, the column 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.
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Srinivasa T N 2020-10-08 06:13:26 Both type of replications from a single server?
Previous Message Dmitry Igrishin 2020-10-07 22:14:02 Re: Which is the setup with lowest resources you know Postgres is used in?