Skip to content

UUID in MSSQL being read as char(36) complicating migration into Postgres. #24168

Closed Answered by hashhar
ak2766 asked this question in Q&A
Discussion options

You must be logged in to vote

The docs are not ideal.

You can cast to UUID from:

  • VARCHAR
  • VARBINARY

So the following works as expected:

trino> use memory.default;
USE
trino:default> create table source (col char(36));
CREATE TABLE
trino:default> create table target (col uuid);
CREATE TABLE
trino:default> insert into source values ('12151fd2-7586-11e9-8f9e-2a86e4085a59');
INSERT: 1 row
trino:default> insert into target select cast(cast(col as varchar) as uuid) from source;
INSERT: 1 row
trino:default> select * from target;
                 col
--------------------------------------
 12151fd2-7586-11e9-8f9e-2a86e4085a59
(1 row)

EDIT: To make it even more clear, the only bit you need is CAST(CAST(col AS VARCHAR) AS UUID)

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by ak2766
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@hashhar
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants