Skip to content

sql: ALTER TABLE ... ADD COLUMN ... PRIMARY KEY doesn't work correctly #81449

@postamar

Description

@postamar

To repro:

CREATE TABLE t (a INT PRIMARY KEY);
ALTER TABLE t ADD COLUMN b INT PRIMARY KEY;

Expected: the primary key is b an error is returned (in pg: multiple primary keys for table "t" are not allowed)
Actual: success, and a subsequent SHOW CREATE TABLE t yields

  table_name |              create_statement
-------------+---------------------------------------------
  t          | CREATE TABLE public.t (
             |     a INT8 NOT NULL,
             |     b INT8 NOT NULL,
             |     CONSTRAINT t_pkey PRIMARY KEY (a ASC),
             |     UNIQUE INDEX t_b_key (b ASC)
             | )
(1 row)

Jira issue: CRDB-15178

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-schema-changesC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions