Subject: [PATCH 2/3] fix

From: Justin Pryzby <[email-masked]>
Date: Sat, 13 Mar 2021 15:51:29 -0600

---
 src/backend/access/gin/ginarrayproc.c | 3 ++-
 src/test/regress/expected/gin.out     | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/backend/access/gin/ginarrayproc.c b/src/backend/access/gin/ginarrayproc.c
index b10bd04ec8..983cc42a86 100644
--- a/src/backend/access/gin/ginarrayproc.c
+++ b/src/backend/access/gin/ginarrayproc.c
@@ -93,7 +93,8 @@ ginqueryarrayextract(PG_FUNCTION_ARGS)
 	if (strategy == GinContainsElemStrategy)
 	{
 		/* single element is passed, set elems to its pointer */
-		elems = &PG_GETARG_DATUM(0);
+		elems = palloc(sizeof(*elems));
+		*elems = PG_GETARG_DATUM(0);
 		nulls = &PG_ARGISNULL(0);
 		nelems = 1;
 	}
diff --git a/src/test/regress/expected/gin.out b/src/test/regress/expected/gin.out
index 698d322e14..7fc7436646 100644
--- a/src/test/regress/expected/gin.out
+++ b/src/test/regress/expected/gin.out
@@ -78,13 +78,13 @@ select count(*) from gin_test_tbl where i @>> 999;
 select count(*) from gin_test_tbl where i @>> 1;
  count 
 -------
-     3
+  2997
 (1 row)
 
 select count(*) from gin_test_tbl where i @>> 999;
  count 
 -------
-     0
+     3
 (1 row)
 
 -- Very weak test for gin_fuzzy_search_limit
-- 
2.17.0

--opg8F0UgoHELSI+9
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0003-fk_arrays_elems.patch"