Hemil: On Wed, Oct 7, 2020 at 2:49 PM Hemil Ruparel <hemilruparel2...@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 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.