mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Fix missing values when doing ALTER TABLE ALTER COLUMN TYPE
This was an oversight in commit 16828d5c
. If the table is going to be
rewritten, we simply clear all the missing values from all the table's
attributes, since there will no longer be any rows with the attributes
missing. Otherwise, we repackage the missing value in an array
constructed with the new type specifications.
Backpatch to release 11.
This fixes bug #15446, reported by Dmitry Molotkov
Reviewed by Dean Rasheed
This commit is contained in:
@ -735,7 +735,44 @@ INSERT INTO leader VALUES (1, 1), (2, 2);
|
||||
ALTER TABLE leader ADD c int;
|
||||
ALTER TABLE leader DROP c;
|
||||
DELETE FROM leader;
|
||||
-- check that ALTER TABLE ... ALTER TYPE does the right thing
|
||||
CREATE TABLE vtype( a integer);
|
||||
INSERT INTO vtype VALUES (1);
|
||||
ALTER TABLE vtype ADD COLUMN b DOUBLE PRECISION DEFAULT 0.2;
|
||||
ALTER TABLE vtype ADD COLUMN c BOOLEAN DEFAULT true;
|
||||
SELECT * FROM vtype;
|
||||
a | b | c
|
||||
---+-----+---
|
||||
1 | 0.2 | t
|
||||
(1 row)
|
||||
|
||||
ALTER TABLE vtype
|
||||
ALTER b TYPE text USING b::text,
|
||||
ALTER c TYPE text USING c::text;
|
||||
NOTICE: rewriting table vtype for reason 4
|
||||
SELECT * FROM vtype;
|
||||
a | b | c
|
||||
---+-----+------
|
||||
1 | 0.2 | true
|
||||
(1 row)
|
||||
|
||||
-- also check the case that doesn't rewrite the table
|
||||
CREATE TABLE vtype2 (a int);
|
||||
INSERT INTO vtype2 VALUES (1);
|
||||
ALTER TABLE vtype2 ADD COLUMN b varchar(10) DEFAULT 'xxx';
|
||||
ALTER TABLE vtype2 ALTER COLUMN b SET DEFAULT 'yyy';
|
||||
INSERT INTO vtype2 VALUES (2);
|
||||
ALTER TABLE vtype2 ALTER COLUMN b TYPE varchar(20) USING b::varchar(20);
|
||||
SELECT * FROM vtype2;
|
||||
a | b
|
||||
---+-----
|
||||
1 | xxx
|
||||
2 | yyy
|
||||
(2 rows)
|
||||
|
||||
-- cleanup
|
||||
DROP TABLE vtype;
|
||||
DROP TABLE vtype2;
|
||||
DROP TABLE follower;
|
||||
DROP TABLE leader;
|
||||
DROP FUNCTION test_trigger();
|
||||
|
@ -481,7 +481,33 @@ ALTER TABLE leader ADD c int;
|
||||
ALTER TABLE leader DROP c;
|
||||
DELETE FROM leader;
|
||||
|
||||
-- check that ALTER TABLE ... ALTER TYPE does the right thing
|
||||
|
||||
CREATE TABLE vtype( a integer);
|
||||
INSERT INTO vtype VALUES (1);
|
||||
ALTER TABLE vtype ADD COLUMN b DOUBLE PRECISION DEFAULT 0.2;
|
||||
ALTER TABLE vtype ADD COLUMN c BOOLEAN DEFAULT true;
|
||||
SELECT * FROM vtype;
|
||||
ALTER TABLE vtype
|
||||
ALTER b TYPE text USING b::text,
|
||||
ALTER c TYPE text USING c::text;
|
||||
SELECT * FROM vtype;
|
||||
|
||||
-- also check the case that doesn't rewrite the table
|
||||
|
||||
CREATE TABLE vtype2 (a int);
|
||||
INSERT INTO vtype2 VALUES (1);
|
||||
ALTER TABLE vtype2 ADD COLUMN b varchar(10) DEFAULT 'xxx';
|
||||
ALTER TABLE vtype2 ALTER COLUMN b SET DEFAULT 'yyy';
|
||||
INSERT INTO vtype2 VALUES (2);
|
||||
|
||||
ALTER TABLE vtype2 ALTER COLUMN b TYPE varchar(20) USING b::varchar(20);
|
||||
SELECT * FROM vtype2;
|
||||
|
||||
|
||||
-- cleanup
|
||||
DROP TABLE vtype;
|
||||
DROP TABLE vtype2;
|
||||
DROP TABLE follower;
|
||||
DROP TABLE leader;
|
||||
DROP FUNCTION test_trigger();
|
||||
|
Reference in New Issue
Block a user