Search code examples
sqlsqliteblobguid

Is it possible to Convert a Sqlite Blob column to a HEX string (GUID)?


I have a SQLite table with a column in it that stores a GUID as a byte array

I am trying to get the a Guid string out of my SQL query. So far I have tried:

Select BlobGuidColumn from [MyTable]

But this returns a blob column

Is it possible to return a Hex string from a SQL query?


Solution

  • Using information from this question: Sqlite: How to cast(data as TEXT) for BLOB and this question: Convert varchar to uniqueidentifier in SQL Server

    I got the answer:

    SELECT substr(hex(BlobGuidColumn), 1, 8) || '-' || substr(hex(BlobGuidColumn), 9, 4) || '-' || substr(hex(BlobGuidColumn), 13, 4) || '-' || substr(hex(BlobGuidColumn), 17, 4) || '-' || substr(hex(BlobGuidColumn), 21, 12) FROM [MyTable]