1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +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:
Tom Lane
2010-06-15 19:04:45 +00:00
parent 7a1d80b91c
commit 7577975515
3 changed files with 99 additions and 38 deletions

View File

@ -678,3 +678,40 @@ SELECT dblink_disconnect('myconn');
-- should get 'connection "myconn" not available' error
SELECT dblink_disconnect('myconn');
ERROR: connection "myconn" not available
-- 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)