Skip to content

sql/schemachanger: implement ALTER DOMAIN ... SET DEFAULT / DROP DEFAULT in declarative schema changer #166935

@bghal

Description

@bghal

Epic: CRDB-62146
Depends on #166933, #166934.

Summary

Implement the SET DEFAULT and DROP DEFAULT subcommands for ALTER DOMAIN in the declarative schema changer. These control the default value expression applied to columns using the domain type.

Implementation Plan

  1. Create pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_domain_set_default.go:

    • alterDomainSetDefault handler: add or replace the DomainTypeDefault element with the new default expression
    • alterDomainDropDefault handler: transition the DomainTypeDefault element to ABSENT
  2. Register both handlers in supportedAlterDomainStatements.

  3. Type-check the default expression against the domain's base type.

  4. Ensure the default expression is serialized correctly in the descriptor.

Key Reference Files

Testing

  • Logic tests: ALTER DOMAIN d SET DEFAULT 42, ALTER DOMAIN d DROP DEFAULT
  • Verify default applies to subsequent INSERTs using the domain type
  • Verify DROP DEFAULT removes the default

Jira issue: CRDB-62162

Metadata

Metadata

Assignees

Labels

C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)target-release-26.3.0

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions