ST_SwapXY()

TL;DR

Use ST_SwapXY() to exchange every X and Y coordinate in a geometry.

Returns a geometry with every coordinate’s X and Y ordinates exchanged.

Syntax

ST_SwapXY(geom)

Arguments

Argument

Description

geom

A GEOMETRY or GEOMETRY32 value.

Return Value

Returns the same geometry family as the input, preserving its SRID metadata.

Usage Notes

  • The function preserves GEOMETRY32, as covered by geo_geometry32.sql.

Examples

DROP DATABASE IF EXISTS geo_swapxy_demo;
CREATE DATABASE geo_swapxy_demo;
USE geo_swapxy_demo;

SELECT ST_AsText(ST_SwapXY(ST_GeomFromText('LINESTRING(0 1,2 3)'))) AS swapped;

DROP DATABASE geo_swapxy_demo;

See Also