Skip to content

Add a type converter for the UUID #120

Closed

Description

@hatarist

There are already some IPv6-related functions (IPv6NumToString and IPv6StringToNum) that help with the type conversion between the user-readable IPv6 address and the FixedString(16)'s value.

It would appear handy to have such like those, but for the UUIDs - it's a pretty common format and it is a bit of pain to work with at the moment:

:) INSERT INTO test (uuid) VALUES (unhex(replaceAll('0964c739-b150-4312-924f-01352d3a4a56', '-', '')));

Ok.

:) SELECT uuid as uuid_binary, replaceRegexpOne(lower(hex(uuid)), '(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})', '\\1-\\2-\\3-\\4-\\5') AS uuid_decoded
FROM test;

┌─uuid_binary─────┬─uuid_decoded──────────────────────────┐
│ \td�9�PC�O5-:JV │ 0964c739-b150-4312-924f-01352d3a4a56   │
└─────────────────┴───────────────────────────────────────┘

I was thinking of a bunch of substring/concat's to improve performance, but it looked much, much uglier :)

Activity

  1. alexey-milovidov commented on Sep 29, 2016

    @alexey-milovidov
    Member

    Yes, proposed UUIDNumToString, UUIDStringToNum functions would be much more convenient.
    Implementation is simple.

  2. hatarist commented on Dec 12, 2016

    @hatarist
    ContributorAuthor

    Functions UUIDNumToString() and UUIDStringToNum() were implemented in d77b4f1 and 31dbff7 by @alexey-milovidov. (#METR-23792)

    Thanks a lot!

    I also referenced these functions in the documentation. Pull request's on its way.

    By the way - just wondering - are we historically keeping NumToString/StringToNum naming convention?
    There is, indeed, IPv4StringToNum, which fits an integer, but IPv6 and UUID are stored in FixedString(16).

    Wouldn't it be better to use something like UUIDBinaryToString or UUIDBytesToString instead?

    I understand that we probably shouldn't rename IPv6-related functions because of the compatibility issues, but on UUIDs it seems to be more straight-forward.

  3. added a commit that references this issue on Dec 12, 2016
  4. alexey-milovidov commented on Dec 12, 2016

    @alexey-milovidov
    Member

    By the way - just wondering - are we historically keeping NumToString/StringToNum naming convention?
    There is, indeed, IPv4StringToNum, which fits an integer, but IPv6 and UUID are stored in FixedString(16).

    Yes. Now we are using "Num" only for consistency with other functions. "Binary" will suite better than "Num". I hope, we will soon introduce function synonims (main reason - to add standard compatible names for existing functions), and we will add IPv6StringToBinary, IPv6BinaryToString, UUIDStringToBinary, UUIDBinaryToString.

  5. added a commit that references this issue on Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions