GoogleCloudPlatform / GoogleCloudPlatform/cloud-spanner-emulator

Emulator does not support setting or dropping NOT NULL on existing columns

Open
#366 1 comment 5 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
334
Forks
77
Avg merge
8m
Merged PRs (30d)
2

Description

Cloud Spanner supports adding and removing NOT NULL constraints on existing non-key columns via `ALTER TABLE ... ALTER COLUMN ... SET NOT NULL` and `DROP NOT NULL`, in both GoogleSQL and PostgreSQL dialects. The emulator does not. It rejects these statements with an internal check failure.

This blocks using the emulator for integration testing when migrations include nullability changes, which is a fairly common schema evolution pattern.

### Repro (PostgreSQL dialect, via PGAdapter)

```sql
CREATE TABLE test (id text PRIMARY KEY, name text);
ALTER TABLE test ALTER COLUMN name SET NOT NULL;
```

The equivalent GoogleSQL statement also fails:

```sql
CREATE TABLE test (id STRING(MAX) NOT NULL, name STRING(MAX)) PRIMARY KEY(id);
ALTER TABLE test ALTER COLUMN name STRING(MAX) NOT NULL;
```

### Expected

Both statements succeed, matching production Spanner behavior.

### Actual

```
ERROR: ZETASQL_RET_CHECK failure (backend/schema/updater/schema_updater.cc:1562)
type == ddl::AlterTable::AlterColumn::SET_DEFAULT || type == ddl::AlterTable::AlterColumn::DROP_DEFAULT
```

The `AlterColumn` handler in `schema_updater.cc` has a check that only passes `SET_DEFAULT` and `DROP_DEFAULT` operations through. Any other alter type (including nullability changes) hits this assertion.

### Versions tested

- `gcr.io/cloud-spanner-pg-adapter/pgadapter-emulator:v0.54.1`
- `gcr.io/cloud-spanner-pg-adapter/pgadapter-emulator:v0.55.1`
- `gcr.io/cloud-spanner-pg-adapter/pgadapter-emulator:latest` (as of 2026-08-10)

All produce the same error.

Contributor guide

Open the contributing guide

Research direction

Start in backend/schema/updater/schema_updater.cc at the AlterColumn handler and reproduce the PostgreSQL and GoogleSQL statements from the issue. Trace how SET NOT NULL and DROP NOT NULL are represented; done means both statements succeed for existing non-key columns without the internal check failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.