diff --git a/contrib/intarray/_int_gist.c b/contrib/intarray/_int_gist.c
index 2c82b86dd1..98145fe370 100644
--- a/contrib/intarray/_int_gist.c
+++ b/contrib/intarray/_int_gist.c
@@ -182,7 +182,8 @@ g_int_compress(PG_FUNCTION_ARGS)
 
 		if (ARRNELEMS(r) >= 2 * num_ranges)
 			ereport(ERROR,
-					(errmsg("input array is too big (%d maximum allowed, %d current), use gist__intbig_ops opclass instead",
+					(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+					 errmsg("input array is too big (%d maximum allowed, %d current), use gist__intbig_ops opclass instead",
 							2 * num_ranges - 1, ARRNELEMS(r))));
 
 		retval = palloc(sizeof(GISTENTRY));
@@ -271,7 +272,8 @@ g_int_compress(PG_FUNCTION_ARGS)
 		lenr = internal_size(dr, len);
 		if (lenr < 0 || lenr > MAXNUMELTS)
 			ereport(ERROR,
-					(errmsg("data is too sparse, recreate index using gist__intbig_ops opclass instead")));
+					(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+					 errmsg("data is too sparse, recreate index using gist__intbig_ops opclass instead")));
 
 		r = resize_intArrayType(r, len);
 		retval = palloc(sizeof(GISTENTRY));
@@ -333,7 +335,8 @@ g_int_decompress(PG_FUNCTION_ARGS)
 	lenr = internal_size(din, lenin);
 	if (lenr < 0 || lenr > MAXNUMELTS)
 		ereport(ERROR,
-				(errmsg("compressed array is too big, recreate index using gist__intbig_ops opclass instead")));
+				(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+				 errmsg("compressed array is too big, recreate index using gist__intbig_ops opclass instead")));
 
 	r = new_intArrayType(lenr);
 	dr = ARRPTR(r);
