Re: tab completion for setting search_path - Mailing list pgsql-hackers

From Andres Freund
Subject Re: tab completion for setting search_path
Date
Msg-id 20140712135128.GD3494@awork2.anarazel.de
Whole thread Raw
In response to Re: tab completion for setting search_path  (Jeff Janes <jeff.janes@gmail.com>)
Responses Re: tab completion for setting search_path  (Christoph Berg <cb@df7cb.de>)
List pgsql-hackers
Hi,

On 2014-06-23 19:57:21 -0700, Jeff Janes wrote:
> diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
> new file mode 100644
> index be5c3c5..dcd1b7d
> *** a/src/bin/psql/tab-complete.c
> --- b/src/bin/psql/tab-complete.c
> *************** psql_completion(const char *text, int st
> *** 3342,3347 ****
> --- 3342,3354 ----
>   
>               COMPLETE_WITH_LIST(my_list);
>           }
> +         else if (pg_strcasecmp(prev2_wd, "search_path") == 0)
> +         {
> +             COMPLETE_WITH_QUERY(Query_for_list_of_schemas
> +                                 " AND nspname not like 'pg\\_toast%%' "
> +                                 " AND nspname not like 'pg\\_temp%%' "
> +                                 " UNION SELECT 'DEFAULT' ");
> +         }
>           else
>           {
>               static const char *const my_list[] =

I don't particularly like the explicit comparisons using LIKE, but we
can't really do better as we only have pg_my_temp_schema(),
pg_is_other_temp_schema() right now. I was tempted to just add
pg_is_temp_schema() and pg_is_toast_schema(), but we couldn't rely on
them for now anyway due to cross version compatibility.

We really should add those functions independently of this though.

I'm also not really happy with the fact that we only complete a single
search_path item. But it's not easy to do better and when looking around
other places (e.g. DROP TABLE) don't support it either.

I've thought about adding "$user" to the set of completed things as
Fujii wondered about it, but it turns out completions containing $ don't
work really great because $ is part of WORD_BREAKS.
E.g. check out what happens if you do
CREATE TABLE "foo$01"();
CREATE TABLE "foo$02"();
DROP TABLE "foo$<tab>
which means that a single schema that requires quoting will break
completion of "$user".

Pushed.

Greetings,

Andres Freund

-- Andres Freund                       http://www.2ndQuadrant.com/PostgreSQL Development, 24x7 Support, Training &
Services



pgsql-hackers by date:

Previous
From: Magnus Hagander
Date:
Subject: SSL information view
Next
From: Tom Lane
Date:
Subject: Re: SSL information view