Re: psql tab completion for DO blocks - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: psql tab completion for DO blocks
Date
Msg-id 201002061911.o16JB3F05941@momjian.us
Whole thread Raw
In response to Re: psql tab completion for DO blocks  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: psql tab completion for DO blocks  (Takahiro Itagaki <itagaki.takahiro@oss.ntt.co.jp>)
List pgsql-hackers
Robert Haas wrote:
> On Sat, Jan 2, 2010 at 7:47 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> > Peter Eisentraut <peter_e@gmx.net> writes:
> >> On l?r, 2010-01-02 at 17:34 -0500, Tom Lane wrote:
> >>> As for the overhead, these queries are not zero-maintenance. ?I still
> >>> think that the usefulness of tab completion here is pretty darn
> >>> minimal,
> >>> since most people are more likely to rely on default_do_language;
> >
> >> We really don't have any data on that, and it doesn't seem all that
> >> likely to me.
> >
> > I'm not really objecting to putting in the patch entirely. ?I'm objecting
> > to carrying an extra completion query for it. ?I don't think hiding
> > languages with laninline=0 improves its usefulness at all, let alone
> > enough to justify extra maintenance burden.
>
> As a practical matter there aren't that many languages in the first
> place, and many of them begin with the same few letters.  If you have
> both plperl and plpython loaded (and they both have inline handlers)
> you'll have to type four characters to disambiguate, and by that time
> (especially for plperl) you might as well just finish typing it by
> hand.
>
> Having said that, I don't see much value in deliberately making the
> tab-completion list fail to match the set of arguments that will
> actually work.  The maintenance burden of an additional query strikes
> me as not worth worrying about.  If David finds it useful and/or has
> users who want it, I think we should just do it.

Where are we on this patch?  We should at least implement the completion
for 'LANGUAGE' in 'DO', and use the existing pg_language query for
completion.  I am attaching a patch that does exactly this.

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: src/bin/psql/tab-complete.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v
retrieving revision 1.192
diff -c -c -r1.192 tab-complete.c
*** src/bin/psql/tab-complete.c    25 Jan 2010 18:23:09 -0000    1.192
--- src/bin/psql/tab-complete.c    6 Feb 2010 19:09:26 -0000
***************
*** 618,624 ****
      static const char *const sql_commands[] = {
          "ABORT", "ALTER", "ANALYZE", "BEGIN", "CHECKPOINT", "CLOSE", "CLUSTER",
          "COMMENT", "COMMIT", "COPY", "CREATE", "DEALLOCATE", "DECLARE",
!         "DELETE FROM", "DISCARD", "DROP", "END", "EXECUTE", "EXPLAIN", "FETCH",
          "GRANT", "INSERT", "LISTEN", "LOAD", "LOCK", "MOVE", "NOTIFY", "PREPARE",
          "REASSIGN", "REINDEX", "RELEASE", "RESET", "REVOKE", "ROLLBACK",
          "SAVEPOINT", "SELECT", "SET", "SHOW", "START", "TABLE", "TRUNCATE", "UNLISTEN",
--- 618,624 ----
      static const char *const sql_commands[] = {
          "ABORT", "ALTER", "ANALYZE", "BEGIN", "CHECKPOINT", "CLOSE", "CLUSTER",
          "COMMENT", "COMMIT", "COPY", "CREATE", "DEALLOCATE", "DECLARE",
!         "DELETE FROM", "DISCARD", "DO", "DROP", "END", "EXECUTE", "EXPLAIN", "FETCH",
          "GRANT", "INSERT", "LISTEN", "LOAD", "LOCK", "MOVE", "NOTIFY", "PREPARE",
          "REASSIGN", "REINDEX", "RELEASE", "RESET", "REVOKE", "ROLLBACK",
          "SAVEPOINT", "SELECT", "SET", "SHOW", "START", "TABLE", "TRUNCATE", "UNLISTEN",
***************
*** 1532,1537 ****
--- 1532,1555 ----
          COMPLETE_WITH_LIST(list_DISCARD);
      }

+ /* DO */
+     /*
+      * Complete DO with LANGUAGE.
+      */
+     else if (pg_strcasecmp(prev_wd, "DO") == 0)
+     {
+         static const char *const list_DO[] =
+         {"LANGUAGE", NULL};
+
+         COMPLETE_WITH_LIST(list_DO);
+     }
+     /*
+      * Complete DO LANGUAGE with in-line-able languages.
+      */
+     else if (pg_strcasecmp(prev2_wd, "DO") == 0 &&
+              pg_strcasecmp(prev_wd, "LANGUAGE") == 0)
+         COMPLETE_WITH_QUERY(Query_for_list_of_languages);
+
  /* DROP (when not the previous word) */
      /* DROP AGGREGATE */
      else if (pg_strcasecmp(prev3_wd, "DROP") == 0 &&

pgsql-hackers by date:

Previous
From: M Z
Date:
Subject: Re: remove contrib/xml2
Next
From: Tom Lane
Date:
Subject: Re: remove contrib/xml2