pgcli icon indicating copy to clipboard operation
pgcli copied to clipboard

Autocomplete not working for "events" table if unquoted

Open owst opened this issue 7 years ago • 1 comments

Description

We have a table named events. Autocomplete doesn't work in query involving this table (at least for a JOIN condition and a SELECT column), unless I quote the table name.

Reproduction

postgres@localhost:postgres> CREATE TABLE events (description text);
CREATE TABLE
Time: 0.012s

Then

postgres@localhost:postgres> SELECT descri* FROM events; 

Cursor at *, having just typed i the completions I see are:

pg_describe_object()                    function  
col_description()                       function  
obj_description()                       function  
shobj_description()                     function  
binary_upgrade_set_record_init_privs()  function  
describe                                keyword   

If I change s/events/"events"/ and retype the i:

postgres@localhost:postgres> SELECT descri FROM "events"; 

then I see:

description                             column    
pg_describe_object()                    function  
col_description()                       function  
obj_description()                       function  
shobj_description()                     function  
binary_upgrade_set_record_init_privs()  function  
describe                                keyword   

as expected.

I'm using Vi-mode, if that matters (I don't think it does). Is this expected, or is there something special about the table name events? Interestingly, if I call the table not_events I don't need to quote the table name for the columns to autocomplete.

Your environment

  • [x] Please provide your OS and version information. Ubuntu 16.04 x64
  • [x] Please provide your CLI version.
> pgcli --version
Version: 2.0.0
  • [x] What is the output of pip freeze command.
(pgcli_issue) > pip freeze
backports.csv==1.0.6
cli-helpers==1.0.2
Click==7.0
configobj==5.0.6
humanize==0.5.1
pgcli==2.0.0
pgspecial==1.11.2
prompt-toolkit==2.0.5
psycopg2==2.7.5
Pygments==2.2.0
setproctitle==1.1.10
six==1.11.0
sqlparse==0.2.4
tabulate==0.8.2
terminaltables==3.1.0
wcwidth==0.1.7

owst avatar Oct 11 '18 16:10 owst

Having dug into this, sqlparse is (incorrectly, for Postgres) treating events as a keyword, rather than an identifier. I've followed up on a promising-sounding PR that would allow us to use sqlparse in "Postgres" mode, where events wouldn't be considered a keyword, but for now, I don't see an easy way to fix this issue

owst avatar Apr 04 '20 11:04 owst