From ded00ed978bfa15591aa30b768400517e539f1c3 Mon Sep 17 00:00:00 2001
From: Jakub Wartak <jakub.wartak@enterprisedb.com>
Date: Tue, 10 Jan 2023 13:11:45 +0100
Subject: [PATCH] psql: warn about CTE queries to be executed without using
 cursor

---
 src/bin/psql/common.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 38f9b10b7c..566f3668e3 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -2241,6 +2241,11 @@ is_select_command(const char *query)
 	if (wordlen == 6 && pg_strncasecmp(query, "values", 6) == 0)
 		return true;
 
+	if (wordlen == 4 && pg_strncasecmp(query, "with", 4) == 0 &&
+			strcasestr(query, "select" ) != NULL)
+		pg_log_warning("attempt to use cursor (due to FETCH_COUNT set) "
+			"has been ignored for WITH/CTE query");
+
 	return false;
 }
 
-- 
2.30.2

