Skip to content

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

Description

@quoral

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)

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

The equivalent GoogleSQL statement also fails:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions