Files
2025-11-30 08:44:54 +08:00

45 lines
1.4 KiB
Markdown

---
slug: /create-spatial-columns
---
# Create a spatial column
seekdb allows you to create a spatial column using the `CREATE TABLE` or `ALTER TABLE` statement.
To create a table with spatial columns using the `CREATE TABLE` statement, see the following syntax example:
```sql
CREATE TABLE geom (g GEOMETRY);
```
To add or remove spatial columns in an existing table using the `ALTER TABLE` statement, see the following syntax example:
```sql
ALTER TABLE geom ADD pt POINT;
ALTER TABLE geom DROP pt;
```
Examples:
```sql
obclient> CREATE TABLE geom (
p POINT SRID 0,
g GEOMETRY NOT NULL SRID 4326
);
Query OK, 0 rows affected
```
The following constraints apply when creating spatial columns:
* You can explicitly specify an SRID when defining a spatial column. If no SRID is defined on the column, the optimizer will not select the spatial index during queries, but index records will still be generated during insert/update operations.
* A spatial index can be defined on a spatial column only after specifying the` NOT NULL` constraint and an SRID. In other words, only columns with a defined SRID can use spatial indexes.
* Once an SRID is defined on a spatial column, attempting to insert values with a different SRID will result in an error.
The following constraints apply to `SRID`:
* You must explicitly specify `SRID` for a spatial column.
* All objects in the column must have the same SRID.