The code to deparse a Var or Param node as a parameter in the query looks same except the member names for getting type and typmod. PFA patch to push that into a function to deduplicate it. Regression and tests in contrib/postgres_fdw run clean with this patch.
--
Best Wishes, Ashutosh Bapat EnterpriseDB Corporation The Postgres Database Company