From 9690c6dfefa60c61cc99691210c31f5bcbfbe706 Mon Sep 17 00:00:00 2001
From: Sami Imseih <simseih@amazon.com>
Date: Wed, 30 Apr 2025 11:21:30 -0500
Subject: [PATCH v1 1/1] Normalize cursor utility statements

---
 src/backend/parser/gram.y      | 18 ++++++++++++++++++
 src/include/nodes/parsenodes.h | 12 +++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 3c4268b271a..c9be19643ac 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -3341,6 +3341,7 @@ ClosePortalStmt:
 					ClosePortalStmt *n = makeNode(ClosePortalStmt);
 
 					n->portalname = $2;
+					n->location = @2;
 					$$ = (Node *) n;
 				}
 			| CLOSE ALL
@@ -3348,6 +3349,7 @@ ClosePortalStmt:
 					ClosePortalStmt *n = makeNode(ClosePortalStmt);
 
 					n->portalname = NULL;
+					n->location = -1;
 					$$ = (Node *) n;
 				}
 		;
@@ -7479,6 +7481,7 @@ fetch_args:	cursor_name
 					n->portalname = $1;
 					n->direction = FETCH_FORWARD;
 					n->howMany = 1;
+					n->location = -1;
 					$$ = (Node *) n;
 				}
 			| from_in cursor_name
@@ -7488,6 +7491,7 @@ fetch_args:	cursor_name
 					n->portalname = $2;
 					n->direction = FETCH_FORWARD;
 					n->howMany = 1;
+					n->location = -1;
 					$$ = (Node *) n;
 				}
 			| NEXT opt_from_in cursor_name
@@ -7497,6 +7501,7 @@ fetch_args:	cursor_name
 					n->portalname = $3;
 					n->direction = FETCH_FORWARD;
 					n->howMany = 1;
+					n->location = -1;
 					$$ = (Node *) n;
 				}
 			| PRIOR opt_from_in cursor_name
@@ -7506,6 +7511,7 @@ fetch_args:	cursor_name
 					n->portalname = $3;
 					n->direction = FETCH_BACKWARD;
 					n->howMany = 1;
+					n->location = -1;
 					$$ = (Node *) n;
 				}
 			| FIRST_P opt_from_in cursor_name
@@ -7515,6 +7521,7 @@ fetch_args:	cursor_name
 					n->portalname = $3;
 					n->direction = FETCH_ABSOLUTE;
 					n->howMany = 1;
+					n->location = -1;
 					$$ = (Node *) n;
 				}
 			| LAST_P opt_from_in cursor_name
@@ -7524,6 +7531,7 @@ fetch_args:	cursor_name
 					n->portalname = $3;
 					n->direction = FETCH_ABSOLUTE;
 					n->howMany = -1;
+					n->location = -1;
 					$$ = (Node *) n;
 				}
 			| ABSOLUTE_P SignedIconst opt_from_in cursor_name
@@ -7533,6 +7541,7 @@ fetch_args:	cursor_name
 					n->portalname = $4;
 					n->direction = FETCH_ABSOLUTE;
 					n->howMany = $2;
+					n->location = @2;
 					$$ = (Node *) n;
 				}
 			| RELATIVE_P SignedIconst opt_from_in cursor_name
@@ -7542,6 +7551,7 @@ fetch_args:	cursor_name
 					n->portalname = $4;
 					n->direction = FETCH_RELATIVE;
 					n->howMany = $2;
+					n->location = @2;
 					$$ = (Node *) n;
 				}
 			| SignedIconst opt_from_in cursor_name
@@ -7551,6 +7561,7 @@ fetch_args:	cursor_name
 					n->portalname = $3;
 					n->direction = FETCH_FORWARD;
 					n->howMany = $1;
+					n->location = @1;
 					$$ = (Node *) n;
 				}
 			| ALL opt_from_in cursor_name
@@ -7560,6 +7571,7 @@ fetch_args:	cursor_name
 					n->portalname = $3;
 					n->direction = FETCH_FORWARD;
 					n->howMany = FETCH_ALL;
+					n->location = -1;
 					$$ = (Node *) n;
 				}
 			| FORWARD opt_from_in cursor_name
@@ -7569,6 +7581,7 @@ fetch_args:	cursor_name
 					n->portalname = $3;
 					n->direction = FETCH_FORWARD;
 					n->howMany = 1;
+					n->location = -1;
 					$$ = (Node *) n;
 				}
 			| FORWARD SignedIconst opt_from_in cursor_name
@@ -7578,6 +7591,7 @@ fetch_args:	cursor_name
 					n->portalname = $4;
 					n->direction = FETCH_FORWARD;
 					n->howMany = $2;
+					n->location = @2;
 					$$ = (Node *) n;
 				}
 			| FORWARD ALL opt_from_in cursor_name
@@ -7596,6 +7610,7 @@ fetch_args:	cursor_name
 					n->portalname = $3;
 					n->direction = FETCH_BACKWARD;
 					n->howMany = 1;
+					n->location = -1;
 					$$ = (Node *) n;
 				}
 			| BACKWARD SignedIconst opt_from_in cursor_name
@@ -7605,6 +7620,7 @@ fetch_args:	cursor_name
 					n->portalname = $4;
 					n->direction = FETCH_BACKWARD;
 					n->howMany = $2;
+					n->location = @2;
 					$$ = (Node *) n;
 				}
 			| BACKWARD ALL opt_from_in cursor_name
@@ -7614,6 +7630,7 @@ fetch_args:	cursor_name
 					n->portalname = $4;
 					n->direction = FETCH_BACKWARD;
 					n->howMany = FETCH_ALL;
+					n->location = -1;
 					$$ = (Node *) n;
 				}
 		;
@@ -12752,6 +12769,7 @@ DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR Select
 					DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
 
 					n->portalname = $2;
+					n->location = @2;
 					/* currently we always set FAST_PLAN option */
 					n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
 					n->query = $7;
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 4610fc61293..14181a48924 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -3387,9 +3387,11 @@ typedef struct SecLabelStmt
 typedef struct DeclareCursorStmt
 {
 	NodeTag		type;
-	char	   *portalname;		/* name of the portal (cursor) */
+	/* name of the portal (cursor) */
+	char	   *portalname pg_node_attr(query_jumble_ignore);
 	int			options;		/* bitmask of options (see above) */
 	Node	   *query;			/* the query (see comments above) */
+	ParseLoc	location pg_node_attr(query_jumble_location);
 } DeclareCursorStmt;
 
 /* ----------------------
@@ -3399,7 +3401,9 @@ typedef struct DeclareCursorStmt
 typedef struct ClosePortalStmt
 {
 	NodeTag		type;
-	char	   *portalname;		/* name of the portal (cursor) */
+	/* name of the portal (cursor) */
+	char	   *portalname pg_node_attr(query_jumble_ignore);
+	ParseLoc	location pg_node_attr(query_jumble_location);
 	/* NULL means CLOSE ALL */
 } ClosePortalStmt;
 
@@ -3423,9 +3427,11 @@ typedef struct FetchStmt
 {
 	NodeTag		type;
 	FetchDirection direction;	/* see above */
-	long		howMany;		/* number of rows, or position argument */
+	/* number of rows, or position argument */
+	long		howMany pg_node_attr(query_jumble_ignore);
 	char	   *portalname;		/* name of portal (cursor) */
 	bool		ismove;			/* true if MOVE */
+	ParseLoc	location pg_node_attr(query_jumble_location);
 } FetchStmt;
 
 /* ----------------------
-- 
2.39.5 (Apple Git-154)

