Please consider attached patch here as earlier attached wrong patch.
Sorry for the inconvenience.
On Mon, Jan 20, 2014 at 1:21 PM, Rushabh Lathia <[email protected]>wrote:
> Hello,
>
> Please consider the following test:
>
> create database foo;
> \c foo
>
> create table foo_test ( a int );
>
> \c postgres
>
> create extension if not exists postgres_fdw;
> create server foo_server foreign data wrapper postgres_fdw options (
> dbname 'foo' );
> create user mapping for current_user server foo_server;
>
> create foreign table foo_test ( a int not null) server foo_server;
>
> -- insert should return error for because NOT NULL constraint on column a
> postgres=# insert into foo_test values ( null );
> INSERT 0 1
>
> postgres=# select * from foo_test;
> a
> ---
>
> (1 row)
>
> -- clean up
> drop foreign table foo_test;
> drop server foo_server cascade;
> \c postgres
> drop database foo;
>
>
> Analysis:
>
> As per the PG documentation it says that foreign table do support the
> NOT NULL, NULL and DEFAULT.
>
> http://www.postgresql.org/docs/devel/static/sql-createforeigntable.html
>
> But when I tried the NOT NULL constraint, its not working for the foreign
> tables.
> Looking at the code into ExecInsert(), for the foreign table missed to call
> ExecConstraints(). I am not sure whether it is intentional that we not
> calling
> ExecConstraints() in case of foreign server or its missed.
> Do share your thought on this.
>
> I quickly fix the issue by adding ExecConstraints() call for foreign table
> and
> now test behaving as expected. PFA patch for the same.
>
> Regards,
> Rushabh Lathia
> www.EnterpriseDB.com
>
>
--
Rushabh Lathia
diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c
index 6f0f47e..f745f5e 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -229,6 +229,12 @@ ExecInsert(TupleTableSlot *slot,
else if (resultRelInfo->ri_FdwRoutine)
{
/*
+ * Check the constraints of the tuple
+ */
+ if (resultRelationDesc->rd_att->constr)
+ ExecConstraints(resultRelInfo, slot, estate);
+
+ /*
* insert into foreign table: let the FDW do it
*/
slot = resultRelInfo->ri_FdwRoutine->ExecForeignInsert(estate,
@@ -641,6 +647,9 @@ ExecUpdate(ItemPointer tupleid,
}
else if (resultRelInfo->ri_FdwRoutine)
{
+ if (resultRelationDesc->rd_att->constr)
+ ExecConstraints(resultRelInfo, slot, estate);
+
/*
* update in foreign table: let the FDW do it
*/
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers