pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Tab completion for AT TIME ZONE
12+ messages / 5 participants
[nested] [flat]

Commits from this thread:
  2023-10-13 d16eb83aba  psql: Add completion support for AT [ LOCAL | TIME ZONE ]
* Tab completion for AT TIME ZONE
@ 2023-03-29 10:28  Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
  0 siblings, 2 replies; 12+ messages in thread

From: Dagfinn Ilmari Mannsåker @ 2023-03-29 10:28 UTC (permalink / raw)
  To: pgsql-hackers

Hi hackers,

A while back we added support for completing time zone names after SET
TIMEZONE, but we failed to do the same for the AT TIME ZONE operator.
Here's a trivial patch for that.

- ilmari

Attachments:

0001-psql-tab-complete-time-zones-after-AT-TIME-ZONE.patch (text/x-diff, 1013B) download From 57138e851552a99174d00a0e48ce55ca3170df75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org> Date: Wed, 29 Mar 2023 11:16:01 +0100 Subject: [PATCH] psql: tab-complete time zones after AT TIME ZONE Commit 7fa3db367986160dee2b2b0bbfb61e1a51d486fd added support for completing time zone names, use that after the AT TIME ZONE operator. --- src/bin/psql/tab-complete.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index e38a49e8bd..9bb8ae0dc3 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -4655,6 +4655,10 @@ psql_completion(const char *text, int start, int end) else if (TailMatches("JOIN")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_selectables); +/* ... AT TIME ZONE ... */ + else if (TailMatches("AT", "TIME", "ZONE")) + COMPLETE_WITH_TIMEZONE_NAME(); + /* Backslash commands */ /* TODO: \dc \dd \dl */ else if (TailMatchesCS("\\?")) -- 2.39.2
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: Tab completion for AT TIME ZONE
@ 2023-03-29 12:41  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
  1 sibling, 0 replies; 12+ messages in thread

From: Pavel Stehule @ 2023-03-29 12:41 UTC (permalink / raw)
  To: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>; +Cc: pgsql-hackers

st 29. 3. 2023 v 12:28 odesílatel Dagfinn Ilmari Mannsåker <
ilmari@ilmari.org> napsal:

> Hi hackers,
>
> A while back we added support for completing time zone names after SET
> TIMEZONE, but we failed to do the same for the AT TIME ZONE operator.
> Here's a trivial patch for that.
>

+1

Pavel


> - ilmari
>
>

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Tab completion for AT TIME ZONE
@ 2023-04-12 17:53  Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
  parent: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
  1 sibling, 1 reply; 12+ messages in thread

From: Dagfinn Ilmari Mannsåker @ 2023-04-12 17:53 UTC (permalink / raw)
  To: pgsql-hackers

Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> writes:

> Hi hackers,
>
> A while back we added support for completing time zone names after SET
> TIMEZONE, but we failed to do the same for the AT TIME ZONE operator.
> Here's a trivial patch for that.

Added to the 2023-07 commitfest:

https://commitfest.postgresql.org/43/4274/

- ilmari





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Tab completion for AT TIME ZONE
@ 2023-04-14 07:42  Jim Jones <jim.jones@uni-muenster.de>
  parent: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
  0 siblings, 1 reply; 12+ messages in thread

From: Jim Jones @ 2023-04-14 07:42 UTC (permalink / raw)
  To: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>; pgsql-hackers

Hi,

Is this supposed to provide tab completion for the AT TIME ZONE operator 
like in this query?

SELECT '2023-04-14 08:00:00' AT TIME ZONE 'Europe/Lisbon';

The patch applied cleanly but I'm afraid I cannot reproduce the intended 
behaviour:

postgres=# SELECT '2023-04-14 08:00:00' AT<tab>

postgres=# SELECT '2023-04-14 08:00:00' AT T<tab>

postgres=# SELECT '2023-04-14 08:00:00' AT TIME Z<tab>

Perhaps I'm testing it in the wrong place?

Best, Jim

On 12.04.23 19:53, Dagfinn Ilmari Mannsåker wrote:
> Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> writes:
>
>> Hi hackers,
>>
>> A while back we added support for completing time zone names after SET
>> TIMEZONE, but we failed to do the same for the AT TIME ZONE operator.
>> Here's a trivial patch for that.
> Added to the 2023-07 commitfest:
>
> https://commitfest.postgresql.org/43/4274/
>
> - ilmari
>
>

Attachments:

  smime.p7s (application/pkcs7-signature, 5.7K) download

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Tab completion for AT TIME ZONE
@ 2023-04-14 09:29  Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
  parent: Jim Jones <jim.jones@uni-muenster.de>
  0 siblings, 1 reply; 12+ messages in thread

From: Dagfinn Ilmari Mannsåker @ 2023-04-14 09:29 UTC (permalink / raw)
  To: Jim Jones <jim.jones@uni-muenster.de>; +Cc: pgsql-hackers

Hi Jim,

Thanks for having a look at my patch, but please don't top post on
PostgreSQL lists.

Jim Jones <jim.jones@uni-muenster.de> writes:

> Hi,
>
> On 12.04.23 19:53, Dagfinn Ilmari Mannsåker wrote:
>> Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> writes:
>>
>>> Hi hackers,
>>>
>>> A while back we added support for completing time zone names after SET
>>> TIMEZONE, but we failed to do the same for the AT TIME ZONE operator.
>>> Here's a trivial patch for that.
>>
>
> Is this supposed to provide tab completion for the AT TIME ZONE operator
> like in this query?
>
> SELECT '2023-04-14 08:00:00' AT TIME ZONE 'Europe/Lisbon';
>
> The patch applied cleanly but I'm afraid I cannot reproduce the intended
> behaviour:
>
> postgres=# SELECT '2023-04-14 08:00:00' AT<tab>
>
> postgres=# SELECT '2023-04-14 08:00:00' AT T<tab>
>
> postgres=# SELECT '2023-04-14 08:00:00' AT TIME Z<tab>
>
> Perhaps I'm testing it in the wrong place?

It doesn't tab complete the AT TIME ZONE operator itself, just the
timezone name after it, so this sholud work:

    # SELECT now() AT TIME ZONE <tab><tab>

or

    # SELECT now() AT TIME ZONE am<tab>


However, looking more closely at the grammar, the word AT only occurs in
AT TIME ZONE, so we could complete the operator itself as well.  Updated
patch attatched.

> Best, Jim

- ilmari

Attachments:

v2-0001-psql-tab-completion-for-AT-TIME-ZONE.patch (text/x-diff, 1.2K) download From 365844db04d27c5bcd1edf8a9d0d44353bc34631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org> Date: Wed, 29 Mar 2023 11:16:01 +0100 Subject: [PATCH v2] psql: tab completion for AT TIME ZONE Commit 7fa3db367986160dee2b2b0bbfb61e1a51d486fd added support for completing time zone names, use that after the AT TIME ZONE operator. Also complete the operator itself, since it's the only thing in the grammar starting with AT. --- src/bin/psql/tab-complete.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c index 5825b2a195..e3870c68e9 100644 --- a/src/bin/psql/tab-complete.c +++ b/src/bin/psql/tab-complete.c @@ -4657,6 +4657,14 @@ psql_completion(const char *text, int start, int end) else if (TailMatches("JOIN")) COMPLETE_WITH_SCHEMA_QUERY(Query_for_list_of_selectables); +/* ... AT TIME ZONE ... */ + else if (TailMatches("AT")) + COMPLETE_WITH("TIME ZONE"); + else if (TailMatches("AT", "TIME")) + COMPLETE_WITH("ZONE"); + else if (TailMatches("AT", "TIME", "ZONE")) + COMPLETE_WITH_TIMEZONE_NAME(); + /* Backslash commands */ /* TODO: \dc \dd \dl */ else if (TailMatchesCS("\\?")) -- 2.39.2
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: Tab completion for AT TIME ZONE
@ 2023-04-14 10:05  Jim Jones <jim.jones@uni-muenster.de>
  parent: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
  0 siblings, 1 reply; 12+ messages in thread

From: Jim Jones @ 2023-04-14 10:05 UTC (permalink / raw)
  To: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>; +Cc: pgsql-hackers

On 14.04.23 11:29, Dagfinn Ilmari Mannsåker wrote:
> It doesn't tab complete the AT TIME ZONE operator itself, just the
> timezone name after it, so this sholud work:
>
>      # SELECT now() AT TIME ZONE <tab><tab>
>
> or
>
>      # SELECT now() AT TIME ZONE am<tab>
>
>
> However, looking more closely at the grammar, the word AT only occurs in
> AT TIME ZONE, so we could complete the operator itself as well.  Updated
> patch attatched.
>
>> Best, Jim
> - ilmari

Got it.

In that case, everything seems to work just fine:

postgres=# SELECT now() AT <tab>

.. autocompletes TIME ZONE :

postgres=# SELECT now() AT TIME ZONE


postgres=# SELECT now() AT TIME ZONE <tab><tab>
Display all 598 possibilities? (y or n)


postgres=# SELECT now() AT TIME ZONE 'Europe/Is<tab><tab>
Europe/Isle_of_Man  Europe/Istanbul


also neglecting the opening single quotes ...

postgres=# SELECT now() AT TIME ZONE Europe/Is<tab>

... autocompletes it after <tab>:

postgres=# SELECT now() AT TIME ZONE 'Europe/Is


The patch applies cleanly and it does what it is proposing. - and it's 
IMHO a very nice addition.

I've marked the CF entry as "Ready for Committer".

Jim






^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Tab completion for AT TIME ZONE
@ 2023-10-12 06:49  Michael Paquier <michael@paquier.xyz>
  parent: Jim Jones <jim.jones@uni-muenster.de>
  0 siblings, 1 reply; 12+ messages in thread

From: Michael Paquier @ 2023-10-12 06:49 UTC (permalink / raw)
  To: Jim Jones <jim.jones@uni-muenster.de>; +Cc: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>; pgsql-hackers

On Fri, Apr 14, 2023 at 12:05:25PM +0200, Jim Jones wrote:
> The patch applies cleanly and it does what it is proposing. - and it's IMHO
> a very nice addition.
> 
> I've marked the CF entry as "Ready for Committer".

+/* ... AT TIME ZONE ... */
+	else if (TailMatches("AT"))
+		COMPLETE_WITH("TIME ZONE");
+	else if (TailMatches("AT", "TIME"))
+		COMPLETE_WITH("ZONE");
+	else if (TailMatches("AT", "TIME", "ZONE"))
+		COMPLETE_WITH_TIMEZONE_NAME();

This style will for the completion of timezone values even if "AT" is
the first word of a query.  Shouldn't this be more selective by making
sure that we are at least in the context of a SELECT query?
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Tab completion for AT TIME ZONE
@ 2023-10-12 09:27  Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
  parent: Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 12+ messages in thread

From: Dagfinn Ilmari Mannsåker @ 2023-10-12 09:27 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Jim Jones <jim.jones@uni-muenster.de>; pgsql-hackers

Michael Paquier <michael@paquier.xyz> writes:

> On Fri, Apr 14, 2023 at 12:05:25PM +0200, Jim Jones wrote:
>> The patch applies cleanly and it does what it is proposing. - and it's IMHO
>> a very nice addition.
>> 
>> I've marked the CF entry as "Ready for Committer".
>
> +/* ... AT TIME ZONE ... */
> +	else if (TailMatches("AT"))
> +		COMPLETE_WITH("TIME ZONE");
> +	else if (TailMatches("AT", "TIME"))
> +		COMPLETE_WITH("ZONE");
> +	else if (TailMatches("AT", "TIME", "ZONE"))
> +		COMPLETE_WITH_TIMEZONE_NAME();
>
> This style will for the completion of timezone values even if "AT" is
> the first word of a query.  Shouldn't this be more selective by making
> sure that we are at least in the context of a SELECT query?

It's valid anywhere an expression is, which is a lot more places than
just SELECT queries.  Off the top of my head I can think of WITH,
INSERT, UPDATE, VALUES, CALL, CREATE TABLE, CREATE INDEX.

As I mentioned upthread, the only place in the grammar where the word AT
occurs is in AT TIME ZONE, so there's no ambiguity.  Also, it doesn't
complete time zone names after AT, it completes the literal words TIME
ZONE, and you have to then hit tab again to get a list of time zones.
If we (or the SQL committee) were to invent more operators that start
with the word AT, we can add those to the first if clause above and
complete with the appropriate values after each one separately.

- ilmari





^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Tab completion for AT TIME ZONE
@ 2023-10-13 01:07  Vik Fearing <vik@postgresfriends.org>
  parent: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
  0 siblings, 1 reply; 12+ messages in thread

From: Vik Fearing @ 2023-10-13 01:07 UTC (permalink / raw)
  To: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>; Michael Paquier <michael@paquier.xyz>; +Cc: Jim Jones <jim.jones@uni-muenster.de>; pgsql-hackers

On 10/12/23 10:27, Dagfinn Ilmari Mannsåker wrote:
> Michael Paquier <michael@paquier.xyz> writes:
> 
>> On Fri, Apr 14, 2023 at 12:05:25PM +0200, Jim Jones wrote:
>>> The patch applies cleanly and it does what it is proposing. - and it's IMHO
>>> a very nice addition.
>>>
>>> I've marked the CF entry as "Ready for Committer".
>>
>> +/* ... AT TIME ZONE ... */
>> +	else if (TailMatches("AT"))
>> +		COMPLETE_WITH("TIME ZONE");
>> +	else if (TailMatches("AT", "TIME"))
>> +		COMPLETE_WITH("ZONE");
>> +	else if (TailMatches("AT", "TIME", "ZONE"))
>> +		COMPLETE_WITH_TIMEZONE_NAME();
>>
>> This style will for the completion of timezone values even if "AT" is
>> the first word of a query.  Shouldn't this be more selective by making
>> sure that we are at least in the context of a SELECT query?
> 
> It's valid anywhere an expression is, which is a lot more places than
> just SELECT queries.  Off the top of my head I can think of WITH,
> INSERT, UPDATE, VALUES, CALL, CREATE TABLE, CREATE INDEX.
> 
> As I mentioned upthread, the only place in the grammar where the word AT
> occurs is in AT TIME ZONE, so there's no ambiguity.  Also, it doesn't
> complete time zone names after AT, it completes the literal words TIME
> ZONE, and you have to then hit tab again to get a list of time zones.
> If we (or the SQL committee) were to invent more operators that start
> with the word AT, we can add those to the first if clause above and
> complete with the appropriate values after each one separately.

Speaking of this...

The SQL committee already has another operator starting with AT which is 
AT LOCAL.  I am implementing it in 
https://commitfest.postgresql.org/45/4343/ where I humbly admit that I 
did not think of psql tab completion at all.

These two patches are co-dependent and whichever goes in first the other 
will need to be adjusted accordingly.
-- 
Vik Fearing






^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Tab completion for AT TIME ZONE
@ 2023-10-13 05:31  Michael Paquier <michael@paquier.xyz>
  parent: Vik Fearing <vik@postgresfriends.org>
  0 siblings, 1 reply; 12+ messages in thread

From: Michael Paquier @ 2023-10-13 05:31 UTC (permalink / raw)
  To: Vik Fearing <vik@postgresfriends.org>; +Cc: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>; Jim Jones <jim.jones@uni-muenster.de>; pgsql-hackers

On Fri, Oct 13, 2023 at 03:07:25AM +0200, Vik Fearing wrote:
> The SQL committee already has another operator starting with AT which is AT
> LOCAL.

The other patch was the reason why I looked at this one.  At the end,
I've made peace with Dagfinn's argument two messages ago, and applied
the patch after adding LOCAL to the keywords, but after also removing
the completion for "ZONE" after typing "AT TIME" because AT would be
completed by "TIME ZONE".

> I am implementing it in https://commitfest.postgresql.org/45/4343/
> where I humbly admit that I did not think of psql tab completion at all.

psql completion is always nice to have but not really mandatory IMO,
so leaving it out if one does not want to implement it is fine by me
to not complicate a patch.  Completion could always be tackled on top
of any feature related to it that got committed.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Tab completion for AT TIME ZONE
@ 2023-10-13 06:01  Vik Fearing <vik@postgresfriends.org>
  parent: Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 12+ messages in thread

From: Vik Fearing @ 2023-10-13 06:01 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>; Jim Jones <jim.jones@uni-muenster.de>; pgsql-hackers

On 10/13/23 06:31, Michael Paquier wrote:
> On Fri, Oct 13, 2023 at 03:07:25AM +0200, Vik Fearing wrote:
>> The SQL committee already has another operator starting with AT which is AT
>> LOCAL.
> 
> The other patch was the reason why I looked at this one. 


Thank you for updating and committing this patch!


> but after also removing
> the completion for "ZONE" after typing "AT TIME" because AT would be
> completed by "TIME ZONE".


Why?  The user can tab at any point.
-- 
Vik Fearing






^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Tab completion for AT TIME ZONE
@ 2023-10-13 07:32  Michael Paquier <michael@paquier.xyz>
  parent: Vik Fearing <vik@postgresfriends.org>
  0 siblings, 0 replies; 12+ messages in thread

From: Michael Paquier @ 2023-10-13 07:32 UTC (permalink / raw)
  To: Vik Fearing <vik@postgresfriends.org>; +Cc: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>; Jim Jones <jim.jones@uni-muenster.de>; pgsql-hackers

On Fri, Oct 13, 2023 at 08:01:08AM +0200, Vik Fearing wrote:
> On 10/13/23 06:31, Michael Paquier wrote:
>> but after also removing
>> the completion for "ZONE" after typing "AT TIME" because AT would be
>> completed by "TIME ZONE".
> 
> Why?  The user can tab at any point.

IMO this leads to unnecessary bloat in tab-complete.c because we
finish with the full completion as long as "TIME" is not fully typed.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 12+ messages in thread


end of thread, other threads:[~2023-10-13 07:32 UTC | newest]

Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-03-29 10:28 Tab completion for AT TIME ZONE Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
2023-03-29 12:41 ` Pavel Stehule <pavel.stehule@gmail.com>
2023-04-12 17:53 ` Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
2023-04-14 07:42   ` Jim Jones <jim.jones@uni-muenster.de>
2023-04-14 09:29     ` Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
2023-04-14 10:05       ` Jim Jones <jim.jones@uni-muenster.de>
2023-10-12 06:49         ` Michael Paquier <michael@paquier.xyz>
2023-10-12 09:27           ` Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
2023-10-13 01:07             ` Vik Fearing <vik@postgresfriends.org>
2023-10-13 05:31               ` Michael Paquier <michael@paquier.xyz>
2023-10-13 06:01                 ` Vik Fearing <vik@postgresfriends.org>
2023-10-13 07:32                   ` Michael Paquier <michael@paquier.xyz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox