How to use the original Guid in the SQL statement

2019-05-07 09:52发布

I know we can

INSERT INTO "Table1" VALUES(X'57A00F3015310D4081AD4ADEF3EBDB5E');

But this little endian format is difficult to compare to the original Guid

300FA057-3115-400D-81AD-4ADEF3EBDB5E

How to use the original Guid in the SQL statement instead of the little endian one?

3条回答
在下西门庆
2楼-- · 2019-05-07 10:22

I'm having similar frustrations and am experimenting with a querying tool to do conversion for me.

For now I get by with something like the below.

select quote(SomeGuid) from MyTable where name = 'Some Name'

Which returns

X'12A0E85D8175514DA792EC3D9A8EFCF7'

Formatting the original guid and comparing to the above:

5DE8A01275814D51A792EC3D9A8EFCF7 -- original no dashes, uppercase 12A0E85D8175514DA792EC3D9A8EFCF7 -- quote(Guid)

I can get away with querying a partial Guid for filtering purposes.

Note % on the right side too - value is quoted

select * from MyTable where quote(SomeGuid) like '%A792EC3D9A8EFCF7%'
查看更多
smile是对你的礼貌
3楼-- · 2019-05-07 10:27

Try this:

INSERT INTO [Table1] ([UID]) VALUES ('{57A00F30-1531-0D40-81AD-4ADEF3EBDB5E}');

I always do in this way, didn't find any problem.

查看更多
聊天终结者
4楼-- · 2019-05-07 10:30

If you want to easily compare to the original without converting then store it as text. It'll take more storage space and will be slower to read/write/compare, but it'll be more human readable.

查看更多
登录 后发表回答