0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

RedshiftでNullが入っているカラムにNot Null制約をかけようとする(ALTER TABLE)とどうなるか?

0
Posted at

結論

エラーになる。

ERROR: ALTER COLUMN SET NOT NULL is not supported

image.png

実行したSQL

準備

CREATE SCHEMA IF NOT EXISTS lab;

DROP TABLE IF EXISTS lab.null_test;
CREATE TABLE lab.null_test (
    id   INTEGER,
    val  VARCHAR(50)      -- NOT NULLなし
);

INSERT INTO lab.null_test (id, val) VALUES
    (1, 'a'),
    (2, NULL),            -- NULLを混ぜる
    (3, 'c');

SELECT * FROM lab.null_test ORDER BY id;

実施

ALTER TABLE lab.null_test ALTER COLUMN val SET NOT NULL;
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?