From 50c19fc76f05124b80fc4c5d20a359c5dbf017af Mon Sep 17 00:00:00 2001
From: Tom Lane
Date: Tue, 12 Mar 2013 18:58:13 -0400
Subject: Fix contrib/postgres_fdw's handling of column defaults.

Adopt the position that only locally-defined defaults matter.  Any defaults
defined in the remote database do not affect insertions performed through
a foreign table (unless they are for columns not known to the foreign
table).  While it'd arguably be more useful to permit remote defaults to be
used, making that work in a consistent fashion requires far more work than
seems possible for 9.3.
---
 contrib/postgres_fdw/sql/postgres_fdw.sql | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

(limited to 'contrib/postgres_fdw/sql/postgres_fdw.sql')

diff --git a/contrib/postgres_fdw/sql/postgres_fdw.sql b/contrib/postgres_fdw/sql/postgres_fdw.sql
index 6df829024d9..70c1e85f325 100644
--- a/contrib/postgres_fdw/sql/postgres_fdw.sql
+++ b/contrib/postgres_fdw/sql/postgres_fdw.sql
@@ -63,23 +63,23 @@ CREATE FOREIGN TABLE ft1 (
 	c4 timestamptz,
 	c5 timestamp,
 	c6 varchar(10),
-	c7 char(10),
+	c7 char(10) default 'ft1',
 	c8 user_enum
 ) SERVER loopback;
 ALTER FOREIGN TABLE ft1 DROP COLUMN c0;
 
 CREATE FOREIGN TABLE ft2 (
-	c0 int,
 	c1 int NOT NULL,
 	c2 int NOT NULL,
+	cx int,
 	c3 text,
 	c4 timestamptz,
 	c5 timestamp,
 	c6 varchar(10),
-	c7 char(10),
+	c7 char(10) default 'ft2',
 	c8 user_enum
 ) SERVER loopback;
-ALTER FOREIGN TABLE ft2 DROP COLUMN c0;
+ALTER FOREIGN TABLE ft2 DROP COLUMN cx;
 
 -- ===================================================================
 -- tests for validator
@@ -286,9 +286,9 @@ INSERT INTO ft2 (c1,c2,c3) VALUES (1104,204,'ddd'), (1105,205,'eee');
 UPDATE ft2 SET c2 = c2 + 300, c3 = c3 || '_update3' WHERE c1 % 10 = 3;
 UPDATE ft2 SET c2 = c2 + 400, c3 = c3 || '_update7' WHERE c1 % 10 = 7 RETURNING *;
 EXPLAIN (verbose, costs off)
-UPDATE ft2 SET c2 = ft2.c2 + 500, c3 = ft2.c3 || '_update9'
+UPDATE ft2 SET c2 = ft2.c2 + 500, c3 = ft2.c3 || '_update9', c7 = DEFAULT
   FROM ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 9;
-UPDATE ft2 SET c2 = ft2.c2 + 500, c3 = ft2.c3 || '_update9'
+UPDATE ft2 SET c2 = ft2.c2 + 500, c3 = ft2.c3 || '_update9', c7 = DEFAULT
   FROM ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 9;
 DELETE FROM ft2 WHERE c1 % 10 = 5 RETURNING *;
 EXPLAIN (verbose, costs off)
@@ -296,8 +296,7 @@ DELETE FROM ft2 USING ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 2;
 DELETE FROM ft2 USING ft1 WHERE ft1.c1 = ft2.c2 AND ft1.c1 % 10 = 2;
 SELECT c1,c2,c3,c4 FROM ft2 ORDER BY c1;
 
--- Test that defaults and triggers on remote table work as expected
-ALTER TABLE "S 1"."T 1" ALTER c6 SET DEFAULT '(^-^;)';
+-- Test that trigger on remote table works as expected
 CREATE OR REPLACE FUNCTION "S 1".F_BRTRIG() RETURNS trigger AS $$
 BEGIN
     NEW.c3 = NEW.c3 || '_trig_update';
-- 
cgit v1.2.3

