pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Shinya11.Kato@nttdata.com
To: masao.fujii@oss.nttdata.com
To: sawada.mshk@gmail.com
Cc: pgsql-hackers@postgresql.org
Subject: RE: [PATCH] Feature improvement for CLOSE, FETCH, MOVE tab completion
Date: Wed, 6 Jan 2021 06:36:05 +0000
Message-ID: <7bf2e1700a7345f79c04fd513675467a@MP-MSGSS-MBX001.msg.nttdata.co.jp> (raw)
In-Reply-To: <697532b0-0a83-7046-1a58-b1ee0f66ac9a@oss.nttdata.com>
References: <b0e4c5c53ef84c5395524f5056fc71f0@MP-MSGSS-MBX001.msg.nttdata.co.jp>
	<CAD21AoBRw9FY6oNj8ubY7XEwJ9Bprfehu88_ePbCfH93JLxWsw@mail.gmail.com>
	<7559e8ee8a0644c8aad79837092143c7@MP-MSGSS-MBX001.msg.nttdata.co.jp>
	<0eab839e-5827-e517-4abf-00b3e581cd45@oss.nttdata.com>
	<CAD21AoBiGkvFpizGAWt-8mQEja3_Afu0pjn09vR1Gk7d+zj_Cw@mail.gmail.com>
	<697532b0-0a83-7046-1a58-b1ee0f66ac9a@oss.nttdata.com>

>+#define Query_for_list_of_cursors \
>+" SELECT name FROM pg_cursors"\
>
>This query should be the following?
>
>" SELECT pg_catalog.quote_ident(name) "\
>"   FROM pg_catalog.pg_cursors "\
>"  WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s'"
>
>+/* CLOSE */
>+	else if (Matches("CLOSE"))
>+		COMPLETE_WITH_QUERY(Query_for_list_of_cursors
>+							" UNION ALL SELECT 'ALL'");
>
>"UNION ALL" should be "UNION"?

Thank you for your advice, and I corrected them.

>> +               COMPLETE_WITH_QUERY(Query_for_list_of_cursors
>> +                                                       " UNION SELECT 'ABSOLUTE'"
>> +                                                       " UNION SELECT 'BACKWARD'"
>> +                                                       " UNION SELECT 'FORWARD'"
>> +                                                       " UNION SELECT 'RELATIVE'"
>> +                                                       " UNION SELECT 'ALL'"
>> +                                                       " UNION SELECT 'NEXT'"
>> +                                                       " UNION SELECT 'PRIOR'"
>> +                                                       " UNION SELECT 'FIRST'"
>> +                                                       " UNION SELECT 'LAST'"
>> +                                                       " UNION SELECT 'FROM'"
>> +                                                       " UNION SELECT 'IN'");
>>
>> This change makes psql unexpectedly output "FROM" and "IN" just after "FETCH".
>
>I think "FROM" and "IN" can be placed just after "FETCH". According to
>the documentation, the direction can be empty. For instance, we can do
>like:

Thank you!

>I've attached the patch improving the tab completion for DECLARE as an
>example. What do you think?
>
>BTW according to the documentation, the options of DECLARE statement
>(BINARY, INSENSITIVE, SCROLL, and NO SCROLL) are order-sensitive.
>
>DECLARE name [ BINARY ] [ INSENSITIVE ] [ [ NO ] SCROLL ]
>    CURSOR [ { WITH | WITHOUT } HOLD ] FOR query
>
>But I realized that these options are actually order-insensitive. For
>instance, we can declare a cursor like:
>
>=# declare abc scroll binary cursor for select * from pg_class;
>DECLARE CURSOR
>
>The both parser code and documentation has been unchanged from 2003.
>Is it a documentation bug?

Thank you for your patch, and it is good.
I cannot find the description "(BINARY, INSENSITIVE, SCROLL, and NO SCROLL) are order-sensitive."
I saw "The key words BINARY, INSENSITIVE, and SCROLL can appear in any order." , according to the documentation.

I made a new patch, but the amount of codes was large due to order-insensitive.
If you know of a better way, please let me know.

Regards,
Shinya Kato


Attachments:

fix_tab_complete_close_fetch_move_v3.patch (application/octet-stream, 5.6K) download diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 3a43c09bf6..4ed241a4ee 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -976,6 +976,11 @@ static const SchemaQuery Query_for_list_of_statistics = { " and pg_catalog.pg_table_is_visible(c2.oid)"\ " and c2.relispartition = 'true'" +#define Query_for_list_of_cursors \ +" SELECT pg_catalog.quote_ident(name) "\ +" FROM pg_catalog.pg_cursors "\ +" WHERE substring(pg_catalog.quote_ident(name),1,%d)='%s'" + /* * These object types were introduced later than our support cutoff of * server version 7.4. We use the VersionedQuery infrastructure so that @@ -2284,6 +2289,10 @@ psql_completion(const char *text, int start, int end) COMPLETE_WITH_VERSIONED_SCHEMA_QUERY(Query_for_list_of_procedures, NULL); else if (Matches("CALL", MatchAny)) COMPLETE_WITH("("); +/* CLOSE */ + else if (Matches("CLOSE")) + COMPLETE_WITH_QUERY(Query_for_list_of_cursors + " UNION SELECT 'ALL'"); /* CLUSTER */ else if (Matches("CLUSTER")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_clusterables, "UNION SELECT 'VERBOSE'"); @@ -3005,8 +3014,43 @@ psql_completion(const char *text, int start, int end) else if (Matches("DECLARE", MatchAny)) COMPLETE_WITH("BINARY", "INSENSITIVE", "SCROLL", "NO SCROLL", "CURSOR"); + else if (Matches("DECLARE", MatchAny, "BINARY")) + COMPLETE_WITH("INSENSITIVE", "SCROLL", "NO SCROLL", "CURSOR"); + else if (Matches("DECLARE", MatchAny, "INSENSITIVE")) + COMPLETE_WITH("BINARY", "SCROLL", "NO SCROLL", "CURSOR"); + else if (Matches("DECLARE", MatchAny, "SCROLL") || + Matches("DECLARE", MatchAny, "NO", "SCROLL")) + COMPLETE_WITH("BINARY", "INSENSITIVE", "CURSOR"); + else if (Matches("DECLARE", MatchAny, "BINARY", "INSENSITIVE") || + Matches("DECLARE", MatchAny, "INSENSITIVE", "BINARY")) + COMPLETE_WITH("SCROLL", "NO SCROLL", "CURSOR"); + else if (Matches("DECLARE", MatchAny, "BINARY", "SCROLL") || + Matches("DECLARE", MatchAny, "BINARY", "NO", "SCROLL") || + Matches("DECLARE", MatchAny, "SCROLL", "BINARY") || + Matches("DECLARE", MatchAny, "NO", "SCROLL", "BINARY")) + COMPLETE_WITH("INSENSITIVE", "CURSOR"); + else if (Matches("DECLARE", MatchAny, "INSENSITIVE", "SCROLL") || + Matches("DECLARE", MatchAny, "INSENSITIVE", "NO", "SCROLL") || + Matches("DECLARE", MatchAny, "SCROLL", "INSENSITIVE") || + Matches("DECLARE", MatchAny, "NO", "SCROLL", "INSENSITIVE")) + COMPLETE_WITH("BINARY", "CURSOR"); + else if (Matches("DECLARE", MatchAny, "BINARY", "INSENSITIVE", "SCROLL") || + Matches("DECLARE", MatchAny, "BINARY", "INSENSITIVE", "NO", "SCROLL") || + Matches("DECLARE", MatchAny, "BINARY", "SCROLL", "INSENSITIVE") || + Matches("DECLARE", MatchAny, "BINARY", "NO", "SCROLL", "INSENSITIVE") || + Matches("DECLARE", MatchAny, "INSENSITIVE", "BINARY", "SCROLL") || + Matches("DECLARE", MatchAny, "INSENSITIVE", "BINARY", "NO", "SCROLL") || + Matches("DECLARE", MatchAny, "INSENSITIVE", "SCROLL", "BINARY") || + Matches("DECLARE", MatchAny, "INSENSITIVE", "NO", "SCROLL", "BINARY") || + Matches("DECLARE", MatchAny, "SCROLL", "BINARY", "INSENSITIVE") || + Matches("DECLARE", MatchAny, "NO", "SCROLL", "BINARY", "INSENSITIVE") || + Matches("DECLARE", MatchAny, "SCROLL", "INSENSITIVE", "BINARY") || + Matches("DECLARE", MatchAny, "NO", "SCROLL", "INSENSITIVE", "BINARY")) + COMPLETE_WITH("CURSOR"); else if (HeadMatches("DECLARE") && TailMatches("CURSOR")) COMPLETE_WITH("WITH HOLD", "WITHOUT HOLD", "FOR"); + else if (HeadMatches("DECLARE") && TailMatches("HOLD")) + COMPLETE_WITH("FOR"); /* DELETE --- can be inside EXPLAIN, RULE, etc */ /* ... despite which, only complete DELETE with FROM at start of line */ @@ -3167,15 +3211,31 @@ psql_completion(const char *text, int start, int end) /* * Complete FETCH with one of ABSOLUTE, BACKWARD, FORWARD, RELATIVE, ALL, - * NEXT, PRIOR, FIRST, LAST + * NEXT, PRIOR, FIRST, LAST, FROM, IN, and a list of cursors */ else if (Matches("FETCH|MOVE")) - COMPLETE_WITH("ABSOLUTE", "BACKWARD", "FORWARD", "RELATIVE", - "ALL", "NEXT", "PRIOR", "FIRST", "LAST"); + COMPLETE_WITH_QUERY(Query_for_list_of_cursors + " UNION SELECT 'ABSOLUTE'" + " UNION SELECT 'BACKWARD'" + " UNION SELECT 'FORWARD'" + " UNION SELECT 'RELATIVE'" + " UNION SELECT 'ALL'" + " UNION SELECT 'NEXT'" + " UNION SELECT 'PRIOR'" + " UNION SELECT 'FIRST'" + " UNION SELECT 'LAST'" + " UNION SELECT 'FROM'" + " UNION SELECT 'IN'"); - /* Complete FETCH BACKWARD or FORWARD with one of ALL, FROM, IN */ + /* + * Complete FETCH BACKWARD or FORWARD with one of ALL, FROM, IN, + * and a list of cursors + */ else if (Matches("FETCH|MOVE", "BACKWARD|FORWARD")) - COMPLETE_WITH("ALL", "FROM", "IN"); + COMPLETE_WITH_QUERY(Query_for_list_of_cursors + " UNION SELECT 'ALL'" + " UNION SELECT 'FROM'" + " UNION SELECT 'IN'"); /* * Complete FETCH <direction> with "FROM" or "IN". These are equivalent, @@ -3185,7 +3245,13 @@ psql_completion(const char *text, int start, int end) else if (Matches("FETCH|MOVE", "ABSOLUTE|BACKWARD|FORWARD|RELATIVE", MatchAnyExcept("FROM|IN")) || Matches("FETCH|MOVE", "ALL|NEXT|PRIOR|FIRST|LAST")) - COMPLETE_WITH("FROM", "IN"); + COMPLETE_WITH_QUERY(Query_for_list_of_cursors + " UNION SELECT 'FROM'" + " UNION SELECT 'IN'"); + /* Complete FETCH <direction> "FROM" or "IN" with a list of cursors */ + else if (HeadMatches("FETCH|MOVE") && + TailMatches("FROM|IN")) + COMPLETE_WITH_QUERY(Query_for_list_of_cursors); /* FOREIGN DATA WRAPPER */ /* applies in ALTER/DROP FDW and in CREATE SERVER */

view thread (22+ messages)  latest in thread

Message-ID: <7bf2e1700a7345f79c04fd513675467a@MP-MSGSS-MBX001.msg.nttdata.co.jp>
Permalink:  ../7bf2e1700a7345f79c04fd513675467a@MP-MSGSS-MBX001.msg.nttdata.co.jp/
Also on:    postgresql.org/message-id/7bf2e1700a7345f79c04fd513675467a@MP-MSGSS-MBX001.msg.nttdata.co.jp

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: Shinya11.Kato@nttdata.com, masao.fujii@oss.nttdata.com, sawada.mshk@gmail.com
  Subject: RE: [PATCH] Feature improvement for CLOSE, FETCH, MOVE tab completion
  In-Reply-To: <7bf2e1700a7345f79c04fd513675467a@MP-MSGSS-MBX001.msg.nttdata.co.jp>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox