Re: psql - missing tab-completion support for tablespaces - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: psql - missing tab-completion support for tablespaces
Date
Msg-id 200408080157.i781v5g29285@candle.pha.pa.us
Whole thread Raw
In response to psql - missing tab-completion support for tablespaces  (Stefan Kaltenbrunner <stefan@kaltenbrunner.cc>)
List pgsql-patches
Yes, I just noticed this myself.

Your patch has been added to the PostgreSQL unapplied patches list at:

    http://momjian.postgresql.org/cgi-bin/pgpatches

It will be applied as soon as one of the PostgreSQL committers reviews
and approves it.

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


Stefan Kaltenbrunner wrote:
> [sorry if you get this mail twice, i think my first post didn't made it
> passt the moderator queue]
>
> Hi!
>
> While playing around with 8.0devel I found it somewhat irritating that
> psql had no tab-complete support for all tablespace related commands.
> Attached is my own poor attempt that adds at least basic support for
> CREATE/ALTER/DROP and \db.
>
> When looking through the code I found that there seem to be much more
> places where the tabcomplete-code is not 100% in sync with what the
> doc's show as possible syntax.
> Is there interest in fixing those up (ie qualifing as BUGS that can get
> fixed during BETA) ? If so I could take a look at those in the next days ...
>
>
> Stefan
>

> Index: src/bin/psql/tab-complete.c
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/tab-complete.c,v
> retrieving revision 1.109
> diff -u -r1.109 tab-complete.c
> --- src/bin/psql/tab-complete.c    28 Jul 2004 14:23:30 -0000    1.109
> +++ src/bin/psql/tab-complete.c    6 Aug 2004 19:52:52 -0000
> @@ -328,6 +328,10 @@
>  "SELECT pg_catalog.quote_ident(datname) FROM pg_catalog.pg_database "\
>  " WHERE substring(pg_catalog.quote_ident(datname),1,%d)='%s'"
>
> +#define Query_for_list_of_tablespaces \
> +"SELECT pg_catalog.quote_ident(spcname) FROM pg_catalog.pg_tablespace "\
> +" WHERE substring(pg_catalog.quote_ident(spcname),1,%d)='%s'"
> +
>  #define Query_for_list_of_encodings \
>  " SELECT DISTINCT pg_catalog.pg_encoding_to_char(conforencoding) "\
>  "   FROM pg_catalog.pg_conversion "\
> @@ -394,6 +398,7 @@
>      {"SCHEMA", Query_for_list_of_schemas},
>      {"SEQUENCE", NULL, &Query_for_list_of_sequences},
>      {"TABLE", NULL, &Query_for_list_of_tables},
> +    {"TABLESPACE", Query_for_list_of_tablespaces},
>      {"TEMP", NULL, NULL},    /* for CREATE TEMP TABLE ... */
>      {"TRIGGER", "SELECT pg_catalog.quote_ident(tgname) FROM pg_catalog.pg_trigger WHERE
substring(pg_catalog.quote_ident(tgname),1,%d)='%s'"},
>      {"TYPE", NULL, &Query_for_list_of_datatypes},
> @@ -575,9 +580,9 @@
>
>      static const char * const backslash_commands[] = {
>          "\\a", "\\connect", "\\C", "\\cd", "\\copy", "\\copyright",
> -        "\\d", "\\da", "\\dc", "\\dC", "\\dd", "\\dD", "\\df", "\\dg", "\\di",
> -        "\\dl", "\\dn", "\\do", "\\dp", "\\ds", "\\dS", "\\dt", "\\dT",
> -        "\\dv", "\\du",
> +        "\\d", "\\da", "\\db", "\\dc", "\\dC", "\\dd", "\\dD", "\\df",
> +        "\\dg", "\\di", "\\dl", "\\dn", "\\do", "\\dp", "\\ds", "\\dS",
> +        "\\dt", "\\dT", "\\dv", "\\du",
>          "\\e", "\\echo", "\\encoding",
>          "\\f", "\\g", "\\h", "\\help", "\\H", "\\i", "\\l",
>          "\\lo_import", "\\lo_export", "\\lo_list", "\\lo_unlink",
> @@ -632,7 +637,7 @@
>               pg_strcasecmp(prev3_wd, "TABLE") != 0)
>      {
>          static const char *const list_ALTER[] =
> -        {"DATABASE", "GROUP", "SCHEMA", "TABLE", "TRIGGER", "USER", NULL};
> +        {"DATABASE", "GROUP", "SCHEMA", "TABLE", "TABLESPACE", "TRIGGER", "USER", NULL};
>
>          COMPLETE_WITH_LIST(list_ALTER);
>      }
> @@ -691,6 +696,16 @@
>               pg_strcasecmp(prev2_wd, "DROP") == 0 &&
>               pg_strcasecmp(prev_wd, "COLUMN") == 0)
>          COMPLETE_WITH_ATTR(prev3_wd);
> +
> +    /* we have ALTER TABLESPACE, so suggest RENAME TO, OWNER TO */
> +    else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
> +             pg_strcasecmp(prev2_wd, "TABLESPACE") == 0)
> +    {
> +        static const char *const list_ALTERTSPC[] =
> +        {"RENAME TO", "OWNER TO", NULL};
> +
> +        COMPLETE_WITH_LIST(list_ALTERTSPC);
> +    }
>
>      /* complete ALTER GROUP <foo> with ADD or DROP */
>      else if (pg_strcasecmp(prev3_wd, "ALTER") == 0 &&
> @@ -985,7 +1000,8 @@
>                                     " UNION SELECT 'DATABASE'"
>                                     " UNION SELECT 'FUNCTION'"
>                                     " UNION SELECT 'LANGUAGE'"
> -                                   " UNION SELECT 'SCHEMA'");
> +                                   " UNION SELECT 'SCHEMA'"
> +                                   " UNION SELECT 'TABLESPACE'");
>
>      /* Complete "GRANT/REVOKE * ON * " with "TO" */
>      else if ((pg_strcasecmp(prev4_wd, "GRANT") == 0 ||
> @@ -1000,6 +1016,8 @@
>              COMPLETE_WITH_QUERY(Query_for_list_of_languages);
>          else if (pg_strcasecmp(prev_wd, "SCHEMA") == 0)
>              COMPLETE_WITH_QUERY(Query_for_list_of_schemas);
> +        else if (pg_strcasecmp(prev_wd, "TABLESPACE") == 0)
> +            COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
>          else
>              COMPLETE_WITH_CONST("TO");
>      }
> @@ -1007,7 +1025,7 @@
>      /*
>       * TODO: to complete with user name we need prev5_wd -- wait for a
>       * more general solution there same for GRANT <sth> ON { DATABASE |
> -     * FUNCTION | LANGUAGE | SCHEMA } xxx TO
> +     * FUNCTION | LANGUAGE | SCHEMA | TABLESPACE } xxx TO
>       */
>
>  /* INSERT */
> @@ -1295,6 +1313,8 @@
>          COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_tisv, NULL);
>      else if (strcmp(prev_wd, "\\da") == 0)
>          COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_aggregates, NULL);
> +    else if (strcmp(prev_wd, "\\db") == 0)
> +        COMPLETE_WITH_QUERY(Query_for_list_of_tablespaces);
>      else if (strcmp(prev_wd, "\\dD") == 0)
>          COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_domains, NULL);
>      else if (strcmp(prev_wd, "\\df") == 0 || strcmp(prev_wd, "\\df+") == 0)
>

>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

--
  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

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: psql groff patch (for 8.1)
Next
From: Tom Lane
Date:
Subject: Re: Tutorial patch