From 16d2cb15ae67beb646ba931993bff15dab356f00 Mon Sep 17 00:00:00 2001
From: Nishant Sharma <nishant.sharma@enterprisedb.com>
Date: Thu, 22 Aug 2024 12:53:43 +0530
Subject: [PATCH v2 1/2] Disallow empty Foreign Table column option name i.e
 (column_name '') for postgres_fdw.

---
 contrib/postgres_fdw/option.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/contrib/postgres_fdw/option.c b/contrib/postgres_fdw/option.c
index 630b304..2f76610 100644
--- a/contrib/postgres_fdw/option.c
+++ b/contrib/postgres_fdw/option.c
@@ -228,6 +228,19 @@ postgres_fdw_validator(PG_FUNCTION_ARGS)
 						 errmsg("invalid value for string option \"%s\": %s",
 								def->defname, value)));
 		}
+		else if (strcmp(def->defname, "column_name") == 0)
+		{
+			char	   *col_name_opt = defGetString(def);
+
+			/*
+			 * PostgresSQL follows SQL syntax, so we do not allow empty
+			 * column_name option.
+			 */
+			if (col_name_opt && col_name_opt[0] == '\0')
+				ereport(ERROR,
+						(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+						 errmsg("colum_name option cannot be empty for postgres_fdw")));
+		}
 	}
 
 	PG_RETURN_VOID();
-- 
1.8.3.1

