Fixing tab-complete for dollar-names
Hi hackers,
In modern versions of Postgres the dollar sign is a totally legal character
for identifiers (except for the first character), but tab-complete do not
treat such identifiers well.
For example if one try to create an Oracle-style view like this:
create view v$activity as select * from pg_stat_activity;
, he will get a normally functioning view, but psql tab-complete will not
help him. Type "v", "v$" or "v$act" and press <TAB> - nothing will be
suggested.
Attached is a small patch fixing this problem.
Honestly I'm a little surprised that this was not done before. Maybe, there
are some special considerations I am not aware of, and the patch will break
something?
What would you say?
--
best regards,
Mikhail A. Gribkov
Attachments:
v001_fix_dollar_names_tab_complete.patchapplication/octet-stream; name=v001_fix_dollar_names_tab_complete.patchDownload
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 677847e434..6de3a2a6af 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -76,7 +76,7 @@
#endif
/* word break characters */
-#define WORD_BREAKS "\t\n@$><=;|&{() "
+#define WORD_BREAKS "\t\n@><=;|&{() "
/*
* Since readline doesn't let us pass any state through to the tab completion
@@ -6030,7 +6030,7 @@ identifier_needs_quotes(const char *ident)
/* Check syntax. */
if (!((ident[0] >= 'a' && ident[0] <= 'z') || ident[0] == '_'))
return true;
- if (strspn(ident, "abcdefghijklmnopqrstuvwxyz0123456789_") != strlen(ident))
+ if (strspn(ident, "abcdefghijklmnopqrstuvwxyz0123456789_$") != strlen(ident))
return true;
/*
Hi hackers,
As not much preliminary interest seem to be here, I'm sending the patch to
the upcoming commitfest
--
best regards,
Mikhail A. Gribkov
On Sat, Jun 17, 2023 at 12:51 AM Mikhail Gribkov <youzhick@gmail.com> wrote:
Show quoted text
Hi hackers,
In modern versions of Postgres the dollar sign is a totally legal
character for identifiers (except for the first character), but
tab-complete do not treat such identifiers well.
For example if one try to create an Oracle-style view like this:create view v$activity as select * from pg_stat_activity;
, he will get a normally functioning view, but psql tab-complete will not
help him. Type "v", "v$" or "v$act" and press <TAB> - nothing will be
suggested.Attached is a small patch fixing this problem.
Honestly I'm a little surprised that this was not done before. Maybe,
there are some special considerations I am not aware of, and the patch will
break something?
What would you say?
--
best regards,
Mikhail A. Gribkov
On 6/26/23 22:10, Mikhail Gribkov wrote:
Hi hackers,
As not much preliminary interest seem to be here, I'm sending the patch to
the upcoming commitfest
I have added myself as reviewer. I already had taken a look at it, and
it seemed okay, but I have not yet searched for corner cases.
--
Vik Fearing
On 27/06/2023 02:47, Vik Fearing wrote:
On 6/26/23 22:10, Mikhail Gribkov wrote:
Hi hackers,
As not much preliminary interest seem to be here, I'm sending the patch to
the upcoming commitfestI have added myself as reviewer. I already had taken a look at it, and
it seemed okay, but I have not yet searched for corner cases.
LGTM, pushed.
I concur it's surprising that no one's noticed or at least not bothered
to fix this before. But I also couldn't find any cases where this would
cause trouble.
--
Heikki Linnakangas
Neon (https://neon.tech)