What's the easiest way to represent a bytea as a single integer in PostgreSQL?

后端 未结 4 1449
星月不相逢
星月不相逢 2021-01-05 15:09

I have a bytea column that contains 14 bytes of data. The last 3 bytes of the 14 contain the CRC code of the data. I would like to extract the CRC as a single i

4条回答
  •  醉酒成梦
    2021-01-05 16:09

    select get_byte(b, 11) * 65536 + get_byte(b, 12) * 256 + get_byte(b, 13)
    from (values ('12345678901234'::bytea)) s(b);
     ?column? 
    ----------
      3289908
    

提交回复
热议问题