Hi All,

Testcase:

create table foo (a  int );
postgres=# SELECT dblink_build_sql_insert('foo','1 2',2,'{\"0\",
\"a\"}','{\"99\", \"xyz\"}');
HINT:  Use the escape string syntax for escapes, e.g., E'\r\n'.
server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

Version: Latest

Description:  The dblink_build_sql_insert()/get_tuple_of_interest functions
is not taking care number of attributes in the target.

PFA patch to fix the same.

Thanks,
Rushabh Lathia
(www.EnterpriseDB.com)
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index 276c7e1..a067309 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -2083,6 +2083,11 @@ get_tuple_of_interest(Oid relid, int2vector *pkattnums, int16 pknumatts, char **
 		/* internal error */
 		elog(ERROR, "SPI connect failure - returned %d", ret);
 
+	if (pknumatts > tupdesc->natts)
+		ereport(ERROR,
+				(errcode(ERRCODE_SYNTAX_ERROR),
+				 errmsg("statement has more expression then specified relation")));
+
 	/*
 	 * Build sql statement to look up tuple of interest Use src_pkattvals as
 	 * the criteria.
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to