Skip to content

ALTER COLUMN ignores SET DEFAULT and DROP DEFAULT #553

Closed

Description

@JanJakes

Reproduction

CREATE TABLE t (id INT, n INT NOT NULL DEFAULT 1, v VARCHAR(10) DEFAULT 'x');

ALTER TABLE t ALTER COLUMN n SET DEFAULT 5;
ALTER TABLE t ALTER COLUMN v DROP DEFAULT;

INSERT INTO t (id) VALUES (1);
SELECT n, v FROM t;
-- 1, 'x'   (MySQL: 5, NULL)

Both ALTER TABLE statements succeed without an error, but nothing changes. SHOW CREATE TABLE and INFORMATION_SCHEMA.COLUMNS still report DEFAULT '1' and DEFAULT 'x'.

Reproduced on trunk at 09963132adefd68dde404959d393aa2200066d44, with PHP 8.5 and SQLite 3.54.1.

Cause

record_alter_table() handles ADD, CHANGE, MODIFY, and DROP actions, but not ALTER [COLUMN] ... SET DEFAULT and DROP DEFAULT. The information schema stays unchanged, and execute_alter_table_statement() then rebuilds the table from it. So the statement copies the whole table, but the table keeps its old defaults.

A possible fix is to record the new default in record_alter_table(), using the same default handling as column definitions, and NULL for DROP DEFAULT.

Related

Activity

  1. changed the title [-]ALTER TABLE ... ALTER COLUMN SET DEFAULT and DROP DEFAULT are ignored[/-] [+]`ALTER COLUMN` with `SET DEFAULT` and `DROP DEFAULT` are ignored[/+] on Oct 22, 2026
  2. changed the title [-]`ALTER COLUMN` with `SET DEFAULT` and `DROP DEFAULT` are ignored[/-] [+]`ALTER COLUMN` ignores `SET DEFAULT` and `DROP DEFAULT`[/+] on Oct 23, 2026
  3. added a commit that references this issue on Oct 23, 2026
    503958e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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