1

I'm reading a rowversion data type from SQL Server using Python and getting back a bytes representation like b'\x00\x00\x00\x00\x00\x00\x18\x9c'.

How can I decode this?

I've tried a few codecs but it's not returning the expected result. Decoded value should be 0x000000000000189c. I'm not seeing much on this data type and what the encoding is so I'm kinda lost.

Edit: I didn't need to decode, I needed to convert from bytes to hex (doh)

nobody
  • 270
  • 2
  • 14
  • What do you mean "how do decode it?" – Thom A Oct 04 '21 at 21:40
  • 1
    There is nothing to decode, it's just a bunch of bytes that identify the LSN when the row was last updated. Perhaps you just want to convert the bytes to a hex string representation https://stackoverflow.com/questions/19210414/byte-array-to-hex-string – Charlieface Oct 04 '21 at 22:33
  • Ah I see, I just need to convert to hex. How do I get the first 0x or is that always the first two characters? – nobody Oct 04 '21 at 23:20

1 Answers1

0

I was mistaken, I don't need to decode. Calling hex() on the bytes gets a close representation as to what it is in SQL Server

b'\x00\x00\x00\x00\x00\x00\x18\x9c'.hex()
'000000000000189c'
nobody
  • 270
  • 2
  • 14