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

后端 未结 4 1417
星月不相逢
星月不相逢 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 15:48

    Well if we're going to do byte-by-byte operations, then bit shifting is probably much more efficient than multiplication.

    Based on Clodoaldo Neto's answer I would then say:

    select (get_byte(arm_data, 11) << 16) |
           (get_byte(arm_data, 12) << 8) |
           (get_byte(arm_data, 13))
                from adsb_raw_message;
    

    Does everyone agree?

提交回复
热议问题