duckdb / duckdb/duckdb-spatial

ALTER TABLE statement cannot add GEOMETRY column

Open
#225 5 comments 0 reactions 0 assignees View on GitHub
bug under review
Dominant language
C
Stars
708
Forks
96
Avg merge
1d 21h
Merged PRs (30d)
5

Description

# Summary

Creating tables with geometry types is possible. Adding geometry columns to an existing table is not, at least not using the `ALTER TABLE` statement.

# Reproducible example
This was the smallest example I could come up with that demonstrates this behavior.

```sql
INSTALL spatial;
LOAD spatial;

BEGIN TRANSACTION;
CREATE TABLE t1(id VARCHAR, pt VARCHAR);
CREATE TABLE t2(id VARCHAR, geom GEOMETRY);
COMMIT;

BEGIN TRANSACTION;
ALTER TABLE t1 ADD COLUMN geom GEOMETRY;
COMMIT;

--undo
BEGIN TRANSACTION;
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
COMMIT;

-- verify that the geometry type is in the catalog:
SELECT COUNT(*) AS res_count FROM duckdb_types() WHERE type_name = 'GEOMETRY';

```

This results in a catalog error:
```
> Catalog Error: Type with name "GEOMETRY" is not in the catalog, but it exists in the spatial extension.
Please try installing and loading the spatial extension: INSTALL spatial; LOAD spatial;
```

If the line with the `ALTER TABLE` statement is commented out, the above SQL will execute successfully, returning the expected value for `res_count`: 1.

# Environment

DuckDB 0.9.2 on Windows 10, executing DuckDB SQL against an in-memory DB via the JDBC driver. I have not yet attempted to reproduce the issue in other environments.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.