What's the “E” before a Postgres string?

前端 未结 2 1266
隐瞒了意图╮
隐瞒了意图╮ 2021-01-07 19:21

I was reading a Postgres/PostGIS statement like this:

SELECT ST_AsBinary(
ST_GeomFromWKB(
  E\'\\\\001\\\\001\\\\000\\\\000\\\\000\\\\321\\\\256B\\\\312O\\\\         


        
2条回答
  •  天涯浪人
    2021-01-07 19:34

    What you see does not look like hexadecimal, because the bytea string literal is in escape string syntax (which is rather outdated nowadays).

    E'\\001\\001\\000\\000\\000\\321\\256B\\312O\\304Q\\300\\347\\030\\220\\275\\336%E@'
    

    The same as "standard conforming string":

    '\001\001\000\000\000\321\256B\312O\304Q\300\347\030\220\275\336%E@'
    

    Both are in "escape format", which can be represented more efficiently in "hex format" as:

    '\x0101000000d1ae42ca4fc451c0e71890bdde254540'
    

    You can use encode() and decode() to transform one form into the other.

    I answered your follow-up question on gis.SE with more details.

提交回复
热议问题