Skip to content

ST_ASBINARY

Converts a GEOGRAPHY object to its Well-Known Binary (WKB) representation.

This function is automatically invoked when casting a GEOGRAPHY to VARBINARY.

Note: The WKB format preserves full numeric precision but does not include the SRID. For an SRID-aware binary format, use ST_ASEWKB.

See also:

Syntax

sql
ST_ASBINARY(<input>)

Arguments

  • <input>: The GEOGRAPHY object to be converted

Returns

Returns a VARBINARY containing the WKB representation of the input GEOGRAPHY.

Example

sql
SELECT ST_AsBinary('POINT(1 1)'::GEOGRAPHY);
-- '\x0101000000000000000000f03f000000000000f03f'

-- Casting works the same way
SELECT 'POINT(1 1)'::GEOGRAPHY::VARBINARY;
-- '\x0101000000000000000000f03f000000000000f03f'