OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

Product Overview
DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.2.1

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & CertificationTicket
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.2.1
    iconOceanBase Database
    SQL - V 4.2.1
    Databases
    • OceanBase Database
    • OceanBase Cloud
    • OceanBase Tugraph
    • Interactive Tutorials
    • OceanBase Best Practices
    Tools
    • OceanBase Cloud Platform
    • OceanBase Migration Service
    • OceanBase Developer Center
    • OceanBase Migration Assessment
    • OceanBase Admin Tool
    • OceanBase Loader and Dumper
    • OceanBase Deployer
    • Kubernetes operator for OceanBase
    • OceanBase Diagnostic Tool
    • OceanBase Binlog Service
    Connectors and Middleware
    • OceanBase Database Proxy
    • Embedded SQL in C for OceanBase
    • OceanBase Call Interface
    • OceanBase Connector/C
    • OceanBase Connector/J
    • OceanBase Connector/ODBC
    • OceanBase Connector/NET
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Spatial data formats

    Last Updated:2026-04-28 09:23:26  Updated
    Share
    What is on this page
    WKT
    Point
    Line
    Polygon
    MultiPoint
    MultiLineString
    MultiPolygon
    GeometryCollection
    WKB
    Point
    LineString
    Polygon
    MultiPoint
    MultiLineString
    MultiPolygon
    GeometryCollection
    Syntactic and geometric validity
    Syntactic validity
    Geometric validity
    GIS examples
    Insert
    Query

    folded

    Share

    OceanBase Database supports two standard spatial data formats to represent geometry objects in a query:

    • Well-known text (WKT)

    • Well-known binary (WKB)

    WKT

    WKT is defined in the extended Backus–Naur form (EBNF). WKT can be used either as a data format (WKT-Data) or as an SRS definition in a GIS (WKT-SRS).

    Point

    A Point has coordinates that are not separated by a comma (,). Here is an example:

    POINT(15 20)
    

    The following examples use the ST_X() function to get the X coordinate from a Point object. The first example directly uses the Point() function to generate an object. The second example uses ST_GeomFromText() to convert a Point into a WKT representation.

    obclient> SELECT ST_X(Point(15, 20));
    +---------------------+
    | ST_X(Point(15, 20)) |
    +---------------------+
    |                  15 |
    +---------------------+
    1 row in set
    
    obclient> SELECT ST_X(ST_GeomFromText('POINT(15 20)'));
    +---------------------------------------+
    | ST_X(ST_GeomFromText('POINT(15 20)')) |
    +---------------------------------------+
    |                                    15 |
    +---------------------------------------+
    1 row in set
    

    Line

    A Line consists of multiple points separated by commas (,). Here is an example:

    LINESTRING(0 0, 10 10, 20 25, 50 60)
    

    Polygon

    A Polygon consists of at least one outer ring and zero or more inner rings. Here is an example:

    POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))
    

    MultiPoint

    A MultiPoint is a collection of points. It is similar to a line, but it has different semantics. Multiple points can be connected to form a line, and can form a MultiPoint as a collection in dispersion. Here is an example:

    MULTIPOINT(0 0, 20 20, 60 60)
    

    In the ST_MPointFromText() and ST_GeoFromText() functions, points in a MultiPoint can also be enclosed in parentheses. Here are some examples:

    ST_MPointFromText('MULTIPOINT (1 1, 2 2, 3 3)')
    ST_MPointFromText('MULTIPOINT ((1 1), (2 2), (3 3))')
    

    MultiLineString

    A MultiLineString is a collection of lines. Here is an example:

    MULTILINESTRING((10 10, 20 20), (15 15, 30 15))
    

    MultiPolygon

    A MultiPolygon is a collection of polygons. Here is an example:

    MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0)),((5 5,7 5,7 7,5 7, 5 5)))
    

    GeometryCollection

    A GeometryCollection is a collection of multiple objects of various base types or collections of various base types.

    GEOMETRYCOLLECTION(POINT(10 10), POINT(30 30), LINESTRING(15 15, 20 20))
    

    WKB

    WKB is a format defined based on the OpenGIS specification and supports seven object types, including Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon, and GeometryCollection.

    Point

    The following table takes POINT(1 -1) as an example to describe the format.

    Component
    Size
    Type
    Value
    Byte order 1 byte Unsigned int 01
    WKB type 4 bytes Unsigned int 01000000
    X coordinate 8 bytes Double-precision 000000000000F03F
    Y coordinate 8 bytes Double-precision 000000000000F0BF

    LineString

    The following table takes LINESTRING(1 -1, -1 1) as an example to describe the format. Num points must be greater than or equal to 2.

    Component
    Size
    Type
    Value
    Byte order 1 byte Unsigned int 01
    WKB type 4 bytes Unsigned int 02000000
    Num points 4 bytes Unsigned int 02000000
    X coordinate 8 bytes Double-precision 000000000000F03F
    Y coordinate 8 bytes Double-precision 000000000000F0BF
    X coordinate 8 bytes Double-precision 000000000000F0BF
    Y coordinate 8 bytes Double-precision 000000000000F03F

    Polygon

    Component
    Size
    Type
    Value
    Byte order 1 byte Unsigned int 01
    WKB type 4 bytes Unsigned int 03000000
    Num rings 4 bytes Unsigned int Greater than or equal to 1
    repeat ring - - -

    MultiPoint

    Component
    Size
    Type
    Value
    Byte order 1 byte Unsigned int 01
    WKB type 4 bytes Unsigned int 04000000
    Num points 4 bytes Unsigned int Num points >= 1
    repeat POINT - - -

    MultiLineString

    Component
    Size
    Type
    Value
    Byte order 1 byte Unsigned int 01
    WKB type 4 bytes Unsigned int 05000000
    Num linestrings 4 bytes Unsigned int Greater than or equal to 1
    repeat LINESTRING - - -

    MultiPolygon

    Component
    Size
    Type
    Value
    Byte order 1 byte Unsigned int 01
    WKB type 4 bytes Unsigned int 06000000
    Num polygons 4 bytes Unsigned int Greater than or equal to 1
    repeat POLYGON - - -

    GeometryCollection

    Component
    Size
    Type
    Value
    Byte order 1 byte Unsigned int 01
    WKB type 4 bytes Unsigned int 07000000
    Num wkbs 4 bytes Unsigned int -
    repeat WKB - - -

    Note

    • Only GeometryCollection can be empty, which means that 0 elements are stored. All other types cannot be empty.
    • LENGTH() for a GIS object returns the binary representation of the length.
    obclient [test]> SET @g = ST_GeomFromText('POINT(1 -1)');
    Query OK, 0 rows affected
    
    obclient [test]> SELECT LENGTH(@g);
    +------------+
    | LENGTH(@g) |
    +------------+
    |         25 |
    +------------+
    1 row in set
    
    obclient [test]> SELECT HEX(@g);
    +----------------------------------------------------+
    | HEX(@g)                                            |
    +----------------------------------------------------+
    | 000000000101000000000000000000F03F000000000000F0BF |
    +----------------------------------------------------+
    1 row in set
    

    Syntactic and geometric validity

    Syntactic validity

    The spatial data must meet the following syntactic validity requirements:

    • A LineString has at least 2 points.
    • A Polygon has at least one ring.
    • A Polygon starts and ends at the same point to form a closed ring.
    • A Polygon has at least 4 points for its outer ring. A Polygon with 3 points is a triangle, with the first and the last points being the same.
    • Only a GeometryCollection can be empty, which means that 0 elements are stored. All other types cannot be empty.

    Geometric validity

    The spatial data must meet the following geometric validity requirements:

    • A Polygon cannot intersect with itself.
    • The outer ring of a Polygon is outside its inner ring.
    • The polygons in a MultiPolygon do not overlap with each other.

    You can use the ST_IsValid() function explicitly check the geometric validity of geometry objects.

    GIS examples

    Insert

    // Place both the conversion function and WKT in the SQL statement.
    INSERT INTO geom VALUES (ST_GeomFromText('POINT(1 1)'));
    
    // Place WKT in the arguments.
    SET @g = 'POINT(1 1)';
    INSERT INTO geom VALUES (ST_GeomFromText(@g));
    
    // Place the conversion expression directly in the arguments.
    SET @g = ST_GeomFromText('POINT(1 1)');
    INSERT INTO geom VALUES (@g);
    
    // Use a unified conversion function.
    SET @g = 'LINESTRING(0 0,1 1,2 2)';
    INSERT INTO geom VALUES (ST_GeomFromText(@g));
    
    SET @g = 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))';
    INSERT INTO geom VALUES (ST_GeomFromText(@g));
    
    SET @g ='GEOMETRYCOLLECTION(POINT(1 1),LINESTRING(0 0,1 1,2 2,3 3,4 4))';
    INSERT INTO geom VALUES (ST_GeomFromText(@g));
    
    // Use a type-based conversion function.
    SET @g = 'POINT(1 1)';
    INSERT INTO geom VALUES (ST_PointFromText(@g));
    
    SET @g = 'LINESTRING(0 0,1 1,2 2)';
    INSERT INTO geom VALUES (ST_LineStringFromText(@g));
    
    SET @g = 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7, 5 5))';
    INSERT INTO geom VALUES (ST_PolygonFromText(@g));
    
    SET @g =
    'GEOMETRYCOLLECTION(POINT(1 1),LINESTRING(0 0,1 1,2 2,3 3,4 4))';
    INSERT INTO geom VALUES (ST_GeomCollFromText(@g));
    
    // It can also be inserted directly based on WKB.
    INSERT INTO geom VALUES(ST_GeomFromWKB(X'0101000000000000000000F03F000000000000F03F'));
    

    Query

    // Perform a query and convert the result into a WKT output.
    SELECT ST_AsText(g) FROM geom;
    
    // Perform a query and convert the result into a WKB output.
    SELECT ST_AsBinary(g) FROM geom;
    

    Previous topic

    Create a spatial index
    Last

    Next topic

    Overview
    Next
    What is on this page
    WKT
    Point
    Line
    Polygon
    MultiPoint
    MultiLineString
    MultiPolygon
    GeometryCollection
    WKB
    Point
    LineString
    Polygon
    MultiPoint
    MultiLineString
    MultiPolygon
    GeometryCollection
    Syntactic and geometric validity
    Syntactic validity
    Geometric validity
    GIS examples
    Insert
    Query