Re: proposal: psql autocomplete for casting

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Kyotaro HORIGUCHI <horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal: psql autocomplete for casting
Date: 2016-03-03 11:15:13
Message-ID: CAFj8pRDB2PpESLxnwNDXmhvTS9VL0NMeAnUdv_hps9WzYwXLjw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2016-03-03 12:06 GMT+01:00 Kyotaro HORIGUCHI <
horiguchi(dot)kyotaro(at)lab(dot)ntt(dot)co(dot)jp>:

> Hello, I considered on this,
>
> At Thu, 3 Mar 2016 10:05:06 +0100, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote in <
> CAFj8pRDZ456OKbpV9jDJ_VCgTWprqxYu1kQp6z_Eu_WgNvs57Q(at)mail(dot)gmail(dot)com>
> > We have not autocomplete for casting introduced by symbol "::". A
> > implementation should not be hard.
>
> Completion needs a sequence of break characters between two
> succeeding words and the break characters cannot be a part of a
> word. If cast operators are allowed to be preceded by white
> space, the following diff gives maybe-desired behavior.
>
> ===
> --- a/src/bin/psql/tab-complete.c
> +++ b/src/bin/psql/tab-complete.c
> @@ -1322,6 +1322,8 @@ psql_completion(const char *text, int start, int end)
> else
> matches = complete_from_variables(text, ":", "",
> true);
> }
> + else if (text[0] == ':' && text[1] == ':')
> + COMPLETE_WITH_LIST3("::integer", "::text", "::date");
>
> /* If no previous word, suggest one of the basic sql commands */
> else if (previous_words_count == 0)
> ===
>
> > =# select 123 ::<tab>
> > ::DATE ::INTEGER ::TEXT
> > =# select 123 ::T<tab>
> > =# select 123 ::TEXT
>
> It might not be instinctive but would be doable by making such a
> candidate list.
>
> ====
> diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
> index 5f27120..179c9f0 100644
> --- a/src/bin/psql/tab-complete.c
> +++ b/src/bin/psql/tab-complete.c
> @@ -1322,6 +1322,8 @@ psql_completion(const char *text, int start, int end)
> else
> matches = complete_from_variables(text, ":", "",
> true);
> }
> + else if (text[0] == ':' && text[1] == ':')
> + COMPLETE_WITH_QUERY("SELECT distinct('::' || typname) FROM
> pg_type where typname !~'^(pg)?_.*'");
>
> /* If no previous word, suggest one of the basic sql commands */
> else if (previous_words_count == 0)
> ====
>
> > =# select 2314 ::t<tab>
> > ::t ::tinterval
> > ::table_constraints ::transforms
> > ::table_privileges ::trigger
> > ::tables ::triggered_update_columns
> > ::text ::triggers
> > ::tid ::tsm_handler
> > ::time ::tsquery
> > ::timestamp ::tsrange
> > ::time_stamp ::tstzrange
> > ::timestamptz ::tsvector
> > ::timetz ::txid_snapshot
>
> Does this make sense?
>

the requirement of space before is not good :( - It should be any different
than operator chars. Not only space.

all other is perfect :)

Regards

Pavel

>
> regards,
>
> --
> Kyotaro Horiguchi
> NTT Open Source Software Center
>
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2016-03-03 11:19:18 Re: Re: redo failed in physical streaming replication while stopping the master server
Previous Message Maton, Brett 2016-03-03 11:11:44 Submit Pull Request