mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Fix dblink_build_sql_insert() and related functions to handle dropped
columns correctly. In passing, get rid of some dead logic in the underlying get_sql_insert() etc functions --- there is no caller that will pass null value-arrays to them. Per bug report from Robert Voinea.
This commit is contained in:
@ -887,3 +887,40 @@ SELECT dblink_disconnect();
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
-- test dropped columns in dblink_build_sql_insert, dblink_build_sql_update
|
||||
CREATE TEMP TABLE test_dropped
|
||||
(
|
||||
col1 INT NOT NULL DEFAULT 111,
|
||||
id SERIAL PRIMARY KEY,
|
||||
col2 INT NOT NULL DEFAULT 112,
|
||||
col2b INT NOT NULL DEFAULT 113
|
||||
);
|
||||
NOTICE: CREATE TABLE will create implicit sequence "test_dropped_id_seq" for serial column "test_dropped.id"
|
||||
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "test_dropped_pkey" for table "test_dropped"
|
||||
INSERT INTO test_dropped VALUES(default);
|
||||
ALTER TABLE test_dropped
|
||||
DROP COLUMN col1,
|
||||
DROP COLUMN col2,
|
||||
ADD COLUMN col3 VARCHAR(10) NOT NULL DEFAULT 'foo',
|
||||
ADD COLUMN col4 INT NOT NULL DEFAULT 42;
|
||||
SELECT dblink_build_sql_insert('test_dropped', '2', 1,
|
||||
ARRAY['1'::TEXT], ARRAY['2'::TEXT]);
|
||||
dblink_build_sql_insert
|
||||
---------------------------------------------------------------------------
|
||||
INSERT INTO test_dropped(id,col2b,col3,col4) VALUES('2','113','foo','42')
|
||||
(1 row)
|
||||
|
||||
SELECT dblink_build_sql_update('test_dropped', '2', 1,
|
||||
ARRAY['1'::TEXT], ARRAY['2'::TEXT]);
|
||||
dblink_build_sql_update
|
||||
-------------------------------------------------------------------------------------------
|
||||
UPDATE test_dropped SET id = '2', col2b = '113', col3 = 'foo', col4 = '42' WHERE id = '2'
|
||||
(1 row)
|
||||
|
||||
SELECT dblink_build_sql_delete('test_dropped', '2', 1,
|
||||
ARRAY['2'::TEXT]);
|
||||
dblink_build_sql_delete
|
||||
-----------------------------------------
|
||||
DELETE FROM test_dropped WHERE id = '2'
|
||||
(1 row)
|
||||
|
||||
|
Reference in New Issue
Block a user