[PATCH] Tab completion for CREATE OR REPLACE
Hello, hackers:
I created a patch about tab completion for command CREATE OR REPLACE in psql
includes:
CREATE [ OR REPLACE ] FUNCTION
CREATE [ OR REPLACE ] PROCEDURE
CREATE [ OR REPLACE ] LANGUAGE
CREATE [ OR REPLACE ] RULE name AS ON event
CREATE [ OR REPLACE ] VIEW AS SELECT
CREATE [ OR REPLACE ] AGGREGATE
CREATE [ OR REPLACE ] TRANSFORM
------------------------------------------------------------------------------------------
Regards
Shenhao Wang
Attachments:
0001-Tab-completion-of-CREATE-OR-REPLACE-in-psql.patchapplication/octet-stream; name=0001-Tab-completion-of-CREATE-OR-REPLACE-in-psql.patchDownload
From 01f6b79043bccdd480504b1128a88410a016772b Mon Sep 17 00:00:00 2001
From: Shenhao Wang <wangsh.fnst@cn.fujitsu.com>
Date: Wed, 21 Aug 2019 18:43:24 +0800
Subject: [PATCH] Tab completion for CREATE OR REPLACE in psql
Tab completion of CREATE OR REPLACE command includes:
CREATE [ OR REPLACE ] FUNCTION
CREATE [ OR REPLACE ] PROCEDURE
CREATE [ OR REPLACE ] LANGUAGE
CREATE [ OR REPLACE ] RULE name AS ON event
CREATE [ OR REPLACE ] VIEW AS SELECT
CREATE [ OR REPLACE ] AGGREGATE
CREATE [ OR REPLACE ] TRANSFORM
---
src/bin/psql/tab-complete.c | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index bcc7404c55..022f518121 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1007,6 +1007,7 @@ static const pgsql_thing_t words_after_create[] = {
{"MATERIALIZED VIEW", NULL, NULL, &Query_for_list_of_matviews},
{"OPERATOR", NULL, NULL, NULL}, /* Querying for this is probably not such
* a good idea. */
+ {"OR REPLACE", NULL, NULL, NULL, THING_NO_DROP | THING_NO_ALTER},
{"OWNED", NULL, NULL, NULL, THING_NO_CREATE | THING_NO_ALTER}, /* for DROP OWNED BY ... */
{"PARSER", Query_for_list_of_ts_parsers, NULL, NULL, THING_NO_SHOW},
{"POLICY", NULL, NULL, NULL},
@@ -1489,6 +1490,11 @@ psql_completion(const char *text, int start, int end)
else if (TailMatches("CREATE"))
matches = completion_matches(text, create_command_generator);
+ /* complete with somthing you can create or replace */
+ else if (TailMatches("CREATE", "OR", "REPLACE"))
+ COMPLETE_WITH("FUNCTION", "PROCEDURE", "LANGUAGE", "RULE", "VIEW",
+ "AGGREGATE", "TRANSFORM");
+
/* DROP, but not DROP embedded in other commands */
/* complete with something you can drop */
else if (Matches("DROP"))
@@ -2345,6 +2351,10 @@ psql_completion(const char *text, int start, int end)
!TailMatches("FOR", MatchAny, MatchAny, MatchAny))
COMPLETE_WITH("(");
+ /* CREATE OR REPLACE */
+ else if (Matches("CREATE", "OR"))
+ COMPLETE_WITH("REPLACE");
+
/* CREATE POLICY */
/* Complete "CREATE POLICY <name> ON" */
else if (Matches("CREATE", "POLICY", MatchAny))
@@ -2440,14 +2450,17 @@ psql_completion(const char *text, int start, int end)
COMPLETE_WITH("publish");
/* CREATE RULE */
- /* Complete "CREATE RULE <sth>" with "AS ON" */
- else if (Matches("CREATE", "RULE", MatchAny))
+ /* Complete "CREATE [ OR REPLACE ] RULE <sth>" with "AS ON" */
+ else if (Matches("CREATE", "RULE", MatchAny) ||
+ Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny))
COMPLETE_WITH("AS ON");
- /* Complete "CREATE RULE <sth> AS" with "ON" */
- else if (Matches("CREATE", "RULE", MatchAny, "AS"))
+ /* Complete "CREATE [ OR REPLACE ] RULE <sth> AS" with "ON" */
+ else if (Matches("CREATE", "RULE", MatchAny, "AS") ||
+ Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny, "AS"))
COMPLETE_WITH("ON");
- /* Complete "CREATE RULE <sth> AS ON" with SELECT|UPDATE|INSERT|DELETE */
- else if (Matches("CREATE", "RULE", MatchAny, "AS", "ON"))
+ /* Complete "CREATE [ OR REPLACE ] RULE <sth> AS ON" with SELECT|UPDATE|INSERT|DELETE */
+ else if (Matches("CREATE", "RULE", MatchAny, "AS", "ON") ||
+ Matches("CREATE", "OR", "REPLACE", "RULE", MatchAny, "AS", "ON"))
COMPLETE_WITH("SELECT", "UPDATE", "INSERT", "DELETE");
/* Complete "AS ON SELECT|UPDATE|INSERT|DELETE" with a "TO" */
else if (TailMatches("AS", "ON", "SELECT|UPDATE|INSERT|DELETE"))
@@ -2726,11 +2739,13 @@ psql_completion(const char *text, int start, int end)
}
/* CREATE VIEW --- is allowed inside CREATE SCHEMA, so use TailMatches */
- /* Complete CREATE VIEW <name> with AS */
- else if (TailMatches("CREATE", "VIEW", MatchAny))
+ /* Complete CREATE [ OR REPLACE ] VIEW <name> with AS */
+ else if (TailMatches("CREATE", "VIEW", MatchAny) ||
+ TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny))
COMPLETE_WITH("AS");
- /* Complete "CREATE VIEW <sth> AS with "SELECT" */
- else if (TailMatches("CREATE", "VIEW", MatchAny, "AS"))
+ /* Complete "CREATE [ OR REPLACE ] VIEW <sth> AS with "SELECT" */
+ else if (TailMatches("CREATE", "VIEW", MatchAny, "AS") ||
+ TailMatches("CREATE", "OR", "REPLACE", "VIEW", MatchAny, "AS"))
COMPLETE_WITH("SELECT");
/* CREATE MATERIALIZED VIEW */
--
2.17.0
On Thu, 22 Aug 2019 at 15:05, Wang, Shenhao <wangsh.fnst@cn.fujitsu.com> wrote:
Hello, hackers:
I created a patch about tab completion for command CREATE OR REPLACE in psql
includes:
CREATE [ OR REPLACE ] FUNCTION
CREATE [ OR REPLACE ] PROCEDURE
CREATE [ OR REPLACE ] LANGUAGE
CREATE [ OR REPLACE ] RULE name AS ON event
CREATE [ OR REPLACE ] VIEW AS SELECT
CREATE [ OR REPLACE ] AGGREGATE
CREATE [ OR REPLACE ] TRANSFORM------------------------------------------------------------------------------------------
Could you add this to the next commitfest?
https://commitfest.postgresql.org/24/
Regards
Ian Barwick
--
Ian Barwick https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
On Thu, Aug 22, 2019 at 3:06 PM Wang, Shenhao
<wangsh.fnst@cn.fujitsu.com> wrote:
Hello, hackers:
I created a patch about tab completion for command CREATE OR REPLACE in psql
includes:
CREATE [ OR REPLACE ] FUNCTION
CREATE [ OR REPLACE ] PROCEDURE
CREATE [ OR REPLACE ] LANGUAGE
CREATE [ OR REPLACE ] RULE name AS ON event
CREATE [ OR REPLACE ] VIEW AS SELECT
CREATE [ OR REPLACE ] AGGREGATE
CREATE [ OR REPLACE ] TRANSFORM
Thanks for the patch! The patch looks good to me.
Barring no objection, I will commit this.
Regards,
--
Fujii Masao
On Tue, Sep 3, 2019 at 11:04 PM Fujii Masao <masao.fujii@gmail.com> wrote:
On Thu, Aug 22, 2019 at 3:06 PM Wang, Shenhao
<wangsh.fnst@cn.fujitsu.com> wrote:Hello, hackers:
I created a patch about tab completion for command CREATE OR REPLACE in psql
includes:
CREATE [ OR REPLACE ] FUNCTION
CREATE [ OR REPLACE ] PROCEDURE
CREATE [ OR REPLACE ] LANGUAGE
CREATE [ OR REPLACE ] RULE name AS ON event
CREATE [ OR REPLACE ] VIEW AS SELECT
CREATE [ OR REPLACE ] AGGREGATE
CREATE [ OR REPLACE ] TRANSFORMThanks for the patch! The patch looks good to me.
Committed. Thanks!
Regards,
--
Fujii Masao