问题
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?
回答1:
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.
回答2:
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%'
回答3:
Try this:
INSERT INTO [Table1] ([UID]) VALUES ('{57A00F30-1531-0D40-81AD-4ADEF3EBDB5E}');
I always do in this way, didn't find any problem.
来源:https://stackoverflow.com/questions/5066392/how-to-use-the-original-guid-in-the-sql-statement-instead-of-the-little-endian-o