Re: Tab completion for AT TIME ZONE - Mailing list pgsql-hackers

From Dagfinn Ilmari Mannsåker
Subject Re: Tab completion for AT TIME ZONE
Date
Msg-id 87pm86reuq.fsf@wibble.ilmari.org
Whole thread Raw
In response to Re: Tab completion for AT TIME ZONE  (Jim Jones <jim.jones@uni-muenster.de>)
Responses Re: Tab completion for AT TIME ZONE  (Jim Jones <jim.jones@uni-muenster.de>)
List 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

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


pgsql-hackers by date:

Previous
From: Jim Jones
Date:
Subject: Re: Adding argument names to aggregate functions
Next
From: Etsuro Fujita
Date:
Subject: Re: Issue in postgres_fdw causing unnecessary wait for cancel request reply