Re: psql tab completion enhancements - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: psql tab completion enhancements
Date
Msg-id 200602121526.k1CFQ9Z28558@candle.pha.pa.us
Whole thread Raw
In response to psql tab completion enhancements  (Joachim Wieland <joe@mcknight.de>)
Responses Re: psql tab completion enhancements  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
I found it was easier to concatenate the "UNION" at the macro call site,
rather than the macro body.  This eliminates the extra macro.  Patch
attached and applied.

---------------------------------------------------------------------------

pgman wrote:
>
> Modified patch attached and applied.
>
> Rather than create the lists in psql, I used UNION SELECT 'KEYWORD' to
> pass the keyword to the backend to be added to the query list.
>
> This was already being done for schema names, and was easy and efficient
> to add.  My addition is even simpler because it just concatenates two
> adjacent strings.  If you have more modifications, please use this
> system.
>
> If you find a macro that needs an 'addon', you can add it as a macro
> parameter to all calls and just use "" if you don't need it.  If any
> macro call uses a non-constant string, you have to make a new *_ADDON
> macro version.
>
> ---------------------------------------------------------------------------
>
> Joachim Wieland wrote:
> > Hi,
> >
> > psql's tab completion has the following problem:
> >
> > If we have the following syntax for example:
> >
> > SET SESSION AUTHORIZATION <user>;
> > SET SESSION AUTHORIZATION DEFAULT;
> >
> > After "SET SESSION AUTHORIZATION", the tab completion can offer a list of
> > roles or the string constant "DEFAULT". However it can't offer both because
> > it can't get a list of roles and add a string constant to this list.
> >
> > The appended patch adds the functionality of lists that can be extended with
> > constants.
> >
> > Then you get:
> >
> > template1=# SET session AUTHORIZATION <tab>
> > DEFAULT  fred     joe      john
> >
> > I did proof-of-concept examples to add a constant to a
> >
> >  - list from a query
> >  - list from a schema query
> >  - list of table attributes
> >
> >
> > Joachim

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/bin/psql/tab-complete.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v
retrieving revision 1.147
diff -c -c -r1.147 tab-complete.c
*** src/bin/psql/tab-complete.c    12 Feb 2006 07:21:40 -0000    1.147
--- src/bin/psql/tab-complete.c    12 Feb 2006 15:05:09 -0000
***************
*** 140,147 ****
  */
  #define COMPLETE_WITH_QUERY(query) \
  do { completion_charp = query; matches = completion_matches(text, complete_from_query); } while(0)
- #define COMPLETE_WITH_QUERY_ADDON(query, addon) \
- do { completion_charp = query addon; matches = completion_matches(text, complete_from_query); } while(0)
  #define COMPLETE_WITH_SCHEMA_QUERY(query, addon) \
  do { completion_squery = &(query); completion_charp = addon; matches = completion_matches(text,
complete_from_schema_query);} while(0) 
  #define COMPLETE_WITH_LIST(list) \
--- 140,145 ----
***************
*** 1657,1663 ****
      else if (pg_strcasecmp(prev3_wd, "SET") == 0
               && pg_strcasecmp(prev2_wd, "SESSION") == 0
               && pg_strcasecmp(prev_wd, "AUTHORIZATION") == 0)
!         COMPLETE_WITH_QUERY_ADDON(Query_for_list_of_roles, " UNION SELECT 'DEFAULT'");
      /* Complete RESET SESSION with AUTHORIZATION */
      else if (pg_strcasecmp(prev2_wd, "RESET") == 0 &&
               pg_strcasecmp(prev_wd, "SESSION") == 0)
--- 1655,1661 ----
      else if (pg_strcasecmp(prev3_wd, "SET") == 0
               && pg_strcasecmp(prev2_wd, "SESSION") == 0
               && pg_strcasecmp(prev_wd, "AUTHORIZATION") == 0)
!         COMPLETE_WITH_QUERY(Query_for_list_of_roles " UNION SELECT 'DEFAULT'");
      /* Complete RESET SESSION with AUTHORIZATION */
      else if (pg_strcasecmp(prev2_wd, "RESET") == 0 &&
               pg_strcasecmp(prev_wd, "SESSION") == 0)

pgsql-patches by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Skipping VACUUM of indexes when no work required
Next
From: Martijn van Oosterhout
Date:
Subject: Re: [HACKERS] Spaces in psql output (Was: FW: PGBuildfarm member snake Branch HEAD Status changed)