Categories:

Geospatial Functions, Conversion Functions

TRY_TO_GEOGRAPHY

Parses an input and returns a value of type GEOGRAPHY.

This function is essentially identical to TO_GEOGRAPHY except that it returns NULL when TO_GEOGRAPHY would issue an error.

See also:

TO_GEOGRAPHY

Syntax

Use one of the following:

TRY_TO_GEOGRAPHY( <varchar_expression> )

TRY_TO_GEOGRAPHY( <binary_expression> )

TRY_TO_GEOGRAPHY( <variant_expression> )

Arguments

varchar_expression

The argument must be a string expression that represents a valid geometric object in one of the following formats:

  • WKT (well-known text).

  • WKB (well-known binary) in hexadecimal format (without a leading 0x).

  • EWKT (extended well-known text).

  • EWKB (extended well-known binary) in hexadecimal format (without a leading 0x).

  • GeoJSON.

binary_expression

The argument must be a binary expression in WKB or EWKB format.

variant_expression

The argument must be an OBJECT in GeoJSON format.

Returns

The function returns a value of type GEOGRAPHY.

Usage Notes

  • Returns NULL if the input cannot be parsed as the appropriate supported format (WKT, WKB, EWKT, EWKB, GeoJSON).

  • Returns NULL if the input format is EWKT or EWKB and the SRID is not 4326. See the note on EWKT and EWKB handling.

Examples

This shows a simple use of the TRY_TO_GEOGRAPHY function with VARCHAR data:

select TRY_TO_GEOGRAPHY('Not a valid input for this data type.');
+-----------------------------------------------------------+
| TRY_TO_GEOGRAPHY('NOT A VALID INPUT FOR THIS DATA TYPE.') |
|-----------------------------------------------------------|
| NULL                                                      |
+-----------------------------------------------------------+