dbcli / pgcli

Postgres CLI with autocompletion and syntax highlighting
http://pgcli.com
BSD 3-Clause "New" or "Revised" License
12.11k stars 557 forks source link

No Auto-complete for tables created during current session #711

Closed jprodman closed 5 years ago

jprodman commented 7 years ago

Description

Awesome tool!

If I create a table in the current session, there is no autocompletion for that table.

> create table foo (id int, xx int); > select * from f "foo" doesn't show up in expansion list.

> select foo. from foo Nothing is suggested after typing "."

This applies for temp tables, too.

environment

OS: CentOS release 6.9 CLI: bash $ pip freeze Babel==2.4.0 Flask==0.12.1 Flask-Migrate==2.0.3 Flask-SQLAlchemy==3.0.dev-20170428 Flask-Script==2.0.5 Jinja2==2.9.6 Mako==1.0.6 MarkupSafe==1.0 Pillow==4.1.1 Pygments==2.2.0 SQLAlchemy==1.1.9 SQLAlchemy-Utils==0.32.14 Sphinx==1.5.5 Werkzeug==0.12.1 alabaster==0.7.10 alembic==0.9.1 aniso8601==1.2.0 arrow==0.10.0 boto==2.46.1 boto3==1.4.4 botocore==1.5.44 click==6.7 configobj==5.0.6 dnspython==1.15.0 docutils==0.13.1 flake8==3.3.0 flask-marshmallow==0.7.0 flask-restplus==0.10.1 freezegun==0.3.8 httpretty==0.8.10 humanize==0.5.1 imagesize==0.7.1 inflection==0.3.1 itsdangerous==0.24 jmespath==0.9.2 jsonschema==2.6.0 livereload==2.5.1 marshmallow==2.13.5 marshmallow-sqlalchemy==0.13.1 mccabe==0.6.1 mock==2.0.0 moto==0.4.31 olefile==0.44 pbr==3.0.0 pdfrw==0.3 pep8-naming==0.4.1 petl==1.1.1 pgcli==1.5.1 pgspecial==1.7.0 pprintpp==0.3.0 prompt-toolkit==1.0.14 psutil==5.2.2 psycopg2==2.7.1 py==1.4.33 py-buzz==0.1.12 pycodestyle==2.3.1 pyflakes==1.5.0 pyftpdlib==1.5.2 pytest==3.0.7 pytest-catchlog==1.2.2 pytest-flask==0.10.0 python-dateutil==2.6.0 python-editor==1.0.3 python-etcd==0.4.5 pytz==2017.2 reportlab==3.4.0 requests==2.13.0 rst2pdf==0.93.dev s3transfer==0.1.10 setproctitle==1.1.10 six==1.10.0 snakeviz==0.4.1 snowballstemmer==1.2.1 sphinx-view==0.1.4 sphinxcontrib-httpdomain==1.5.0 sqlalchemy-postgres-copy==0.5.0 sqlparse==0.2.3 tornado==4.5.1 uWSGI==2.0.15 urllib3==1.21 wcwidth==0.1.7 xmltodict==0.11.0

duplicate-issues[bot] commented 7 years ago

Hey @jprodman,

We did a quick check and this issue looks very darn similar to

This could be a coincidence, but if any of these issues solves your problem then I did a good job :smile:

If not, the maintainers will get to this issue shortly.

Cheers, Your Friendly Neighborhood ProBot

amjith commented 7 years ago

@jprodman We trigger an auto-completion refresh anytime the user runs a command that could change database structure. For example, we run it after CREATE, DROP etc.

I just tried it out on my local instance I created a new table (called 'foo') and in the next statement SELECT * FROM f does list foo. So I have a couple of questions:

  1. Did you create the table using pgcli in the same session or was the table created outside of pgcli?
  2. While the completion refresh is going on in the background, we usually display a message in the toolbar that says "Refreshing completions", do you see that message right after you run the CREATE command?
koljonen commented 7 years ago

If the object creation hasn't been committed, the object won't be seen by the connection that's used for refreshing completions. I don't think we can do much about that while using a separate connection for the completer. What we could do something about is that the new object won't be seen after COMMIT either, by doing another refresh.

You can however avoid the problem by starting pgcli with the --single-connection flag, which will use the same connection for metadata as for user queries/commands.

EDIT: We should also do a refresh after ROLLBACK. In single-connection mode, we get phantom completions after rolling back object creation.

j-bennet commented 5 years ago

Closed via https://github.com/dbcli/pgcli/pull/724.