Re: tab completion for setting search_path

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Kevin Grittner <kgrittn(at)ymail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Ian Barwick <ian(at)2ndquadrant(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: tab completion for setting search_path
Date: 2014-07-12 13:51:28
Message-ID: 20140712135128.GD3494@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2014-07-12 14:36:04 Re: SSL information view
Previous Message Magnus Hagander 2014-07-12 13:08:01 SSL information view