Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I read this example of a WKB (well know binary) from "PostGIS in Action" 2ed.:


I understand the E'..' is an escape string, and the escaped backslash is a separator. But I don't understand the rest of the well-known binary.

Can anyone explain what are the numbers and letters?

They do not look like hexidecimal according to wikipedia consider e.g. 304Q. Also the 336%E@ looks weird.

share|improve this question
This question is a follow-up to:… – Erwin Brandstetter Jan 16 at 5:37
up vote 6 down vote accepted

ST_GeomFromWKB() takes the a WKB as input data type bytea.

Not sure why your example uses the old escape string syntax for the string literal. Maybe because the examples in the manual still do so, too. (About time somebody updates it.) It's not wrong, just unnecessarily noisy. Unless you are running a very old Postgres instance with the setting standard_conforming_strings = off, you can replace it with the modern, standard form:

ST_GeomFromWKB('\001\001\000\000\000\321\256B\312O\304Q\300\347\030\220\275\336%E@', 4326));

The above is the escape format for a bytea literal. The manual advises:

... this format should probably be avoided for most new applications.

So, double "old-school" syntax. Alternatively, you can use the shorter hex format:

SELECT ST_AsBinary(ST_GeomFromWKB('\x0101000000d1ae42ca4fc451c0e71890bdde254540', 4326));


share|improve this answer

It's a type of binary encoding, which can be converted using encode and decode functions. There are several binary encodings, such as base64, hex, and escape (default). Most folks that show WKB as hex-encoded text, which uses digits 0-9 and characters A-F (upper or lower case).

Here is a demo, where all of the outputs are text:

  encode(b, 'base64') AS encode_base64,
  encode(b, 'escape') AS encode_escape,
  encode(b, 'hex') AS encode_hex,
  ST_AsEWKT(encode(b, 'hex')::geometry)
  SELECT '\001\001\000\000\000\321\256B\312O\304Q\300\347\030\220\275\336%E@'::bytea AS b
) d;

-[ RECORD 1 ]-+-------------------------------------------------------------------
encode_base64 | AQEAAADRrkLKT8RRwOcYkL3eJUVA
encode_escape | \x01\x01\000\000\000\321\256B\312O\304Q\300\347\x18\220\275\336%E@
encode_hex    | 0101000000d1ae42ca4fc451c0e71890bdde254540
st_asewkt     | POINT(-71.06737 42.29586)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.