[PATCH] Tiny CREATE STATISTICS tab-completion cleanup

Started by Nonameabout 7 years ago3 messages
#1Noname
ilmari@ilmari.org
1 attachment(s)

Hi Hackers,

As I was hacking on the CREATE TABLE tab completions, I noticed that the
CREATE STATISTICS completion was checking manually for the start and end
of the parenthesised list instead of using the "(*)" wildcard (because
it predates that functionality). Attached is a patch that updates it to
use the modern syntax.

- ilmari
--
"I use RMS as a guide in the same way that a boat captain would use
a lighthouse. It's good to know where it is, but you generally
don't want to find yourself in the same spot." - Tollef Fog Heen

Attachments:

0001-Use-wildcard-to-match-parens-after-CREATE-STATISTICS.patchtext/x-diffDownload
From dc4940b937f3e3d51fb76bfa970aac15be9476d2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Fri, 23 Nov 2018 15:21:22 +0000
Subject: [PATCH 1/2] Use wildcard to match parens after CREATE STATISTICS

Now that * can match in the middle of an alternative, we can use "(*)"
to match the whole parenthesised list, instead of checking manually
for the '(' and ')'.
---
 src/bin/psql/tab-complete.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 9dbd555166..90cc1fe215 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -2390,9 +2390,7 @@ psql_completion(const char *text, int start, int end)
 		COMPLETE_WITH("(", "ON");
 	else if (Matches("CREATE", "STATISTICS", MatchAny, "("))
 		COMPLETE_WITH("ndistinct", "dependencies");
-	else if (HeadMatches("CREATE", "STATISTICS", MatchAny) &&
-			 previous_words[0][0] == '(' &&
-			 previous_words[0][strlen(previous_words[0]) - 1] == ')')
+	else if (Matches("CREATE", "STATISTICS", MatchAny, "(*)"))
 		COMPLETE_WITH("ON");
 	else if (HeadMatches("CREATE", "STATISTICS", MatchAny) &&
 			 TailMatches("FROM"))
-- 
2.19.2

#2Tomas Vondra
tomas.vondra@2ndquadrant.com
In reply to: Noname (#1)
Re: [PATCH] Tiny CREATE STATISTICS tab-completion cleanup

Hi,

On 11/26/18 5:49 PM, Dagfinn Ilmari Mannsåker wrote:

Hi Hackers,

As I was hacking on the CREATE TABLE tab completions, I noticed that the
CREATE STATISTICS completion was checking manually for the start and end
of the parenthesised list instead of using the "(*)" wildcard (because
it predates that functionality). Attached is a patch that updates it to
use the modern syntax.

Makes sense. At first I was wondering why it was not modified by the
patch introducing the "(*)" wildcard, but I see 121213d9 only cared
about VACUUM, EXPLAIN and ANALYZE.

The patch seems fine to me, I'll get it committed.

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#3Tomas Vondra
tomas.vondra@2ndquadrant.com
In reply to: Tomas Vondra (#2)
Re: [PATCH] Tiny CREATE STATISTICS tab-completion cleanup

On 11/27/18 12:55 AM, Tomas Vondra wrote:

Hi,

On 11/26/18 5:49 PM, Dagfinn Ilmari Mannsåker wrote:

Hi Hackers,

As I was hacking on the CREATE TABLE tab completions, I noticed that the
CREATE STATISTICS completion was checking manually for the start and end
of the parenthesised list instead of using the "(*)" wildcard (because
it predates that functionality). Attached is a patch that updates it to
use the modern syntax.

Makes sense. At first I was wondering why it was not modified by the
patch introducing the "(*)" wildcard, but I see 121213d9 only cared
about VACUUM, EXPLAIN and ANALYZE.

The patch seems fine to me, I'll get it committed.

Pushed. Thanks for the patch.

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services