OceanBase Database allows you to use CREATE TABLE or ALTER TABLE to create spatial columns.
The syntax of the CREATE TABLE statement for creating a table with spatial columns is as follows:
CREATE TABLE geom (g GEOMETRY);
The syntax of the ALTER TABLE statement for adding a spatial column to or deleting a spatial column from a table is as follows:
ALTER TABLE geom ADD pt POINT;
ALTER TABLE geom DROP pt;
Example:
obclient> CREATE TABLE geom (
p POINT SRID 0,
g GEOMETRY NOT NULL SRID 4326
);
Query OK, 0 rows affected
When you create spatial columns, observe the following constraints:
When you define a spatial column, you can explicitly specify the SRID. If no SRID is defined for a column, the optimizer does not select spatial indexes for a query, but still generates index records for insert and update operations.
If you have specified the
NOT NULLconstraint and an SRID for a spatial column, you can define spatial indexes on the spatial column. In other words, only columns defined with SRIDs can use spatial indexes.If you have defined an SRID for a spatial column, an error will be reported when you insert other SRID values.
SRIDs are subject to the following constraints:
The specified SRID is displayed on the spatial column.
The SRID must be the same for all objects in a column.