Postgres CLI with autocompletion and syntax highlighting

Overview

A REPL for Postgres

Build Status Code coverage report Latest Version Code Health

This is a postgres client that does auto-completion and syntax highlighting.

Home Page: http://pgcli.com

MySQL Equivalent: http://mycli.net

screenshots/pgcli.gif

screenshots/image01.png

Quick Start

If you already know how to install python packages, then you can simply do:

$ pip install -U pgcli

or

$ sudo apt-get install pgcli # Only on Debian based Linux (e.g. Ubuntu, Mint, etc)
$ brew install pgcli  # Only on macOS

If you don't know how to install python packages, please check the detailed instructions.

If you are restricted to using psycopg2 2.7.x then pip will try to install it from a binary. There are some known issues with the psycopg2 2.7 binary - see the psycopg docs for more information about this and how to force installation from source. psycopg2 2.8 has fixed these problems, and will build from source.

Usage

$ pgcli [database_name]

or

$ pgcli postgresql://[user[:password]@][netloc][:port][/dbname][?extra=value[&other=other-value]]

Examples:

$ pgcli local_database

$ pgcli postgres://amjith:[email protected].com:5432/app_db?sslmode=verify-ca&sslrootcert=/myrootcert

For more details:

$ pgcli --help

Usage: pgcli [OPTIONS] [DBNAME] [USERNAME]

Options:
  -h, --host TEXT            Host address of the postgres database.
  -p, --port INTEGER         Port number at which the postgres instance is
                             listening.
  -U, --username TEXT        Username to connect to the postgres database.
  -u, --user TEXT            Username to connect to the postgres database.
  -W, --password             Force password prompt.
  -w, --no-password          Never prompt for password.
  --single-connection        Do not use a separate connection for completions.
  -v, --version              Version of pgcli.
  -d, --dbname TEXT          database name to connect to.
  --pgclirc FILE             Location of pgclirc file.
  -D, --dsn TEXT             Use DSN configured into the [alias_dsn] section
                             of pgclirc file.
  --list-dsn                 list of DSN configured into the [alias_dsn]
                             section of pgclirc file.
  --row-limit INTEGER        Set threshold for row limit prompt. Use 0 to
                             disable prompt.
  --less-chatty              Skip intro on startup and goodbye on exit.
  --prompt TEXT              Prompt format (Default: "\[email protected]\h:\d> ").
  --prompt-dsn TEXT          Prompt format for connections using DSN aliases
                             (Default: "\[email protected]\h:\d> ").
  -l, --list                 list available databases, then exit.
  --auto-vertical-output     Automatically switch to vertical output mode if
                             the result is wider than the terminal width.
  --warn [all|moderate|off]  Warn before running a destructive query.
  --help                     Show this message and exit.

pgcli also supports many of the same environment variables as psql for login options (e.g. PGHOST, PGPORT, PGUSER, PGPASSWORD, PGDATABASE).

The SSL-related environment variables are also supported, so if you need to connect a postgres database via ssl connection, you can set set environment like this:

export PGSSLMODE="verify-full"
export PGSSLCERT="/your-path-to-certs/client.crt"
export PGSSLKEY="/your-path-to-keys/client.key"
export PGSSLROOTCERT="/your-path-to-ca/ca.crt"
pgcli -h localhost -p 5432 -U username postgres

Features

The pgcli is written using prompt_toolkit.

  • Auto-completes as you type for SQL keywords as well as tables and columns in the database.

  • Syntax highlighting using Pygments.

  • Smart-completion (enabled by default) will suggest context-sensitive completion.

    • SELECT * FROM <tab> will only show table names.
    • SELECT * FROM users WHERE <tab> will only show column names.
  • Primitive support for psql back-slash commands.

  • Pretty prints tabular data.

Config

A config file is automatically created at ~/.config/pgcli/config at first launch. See the file itself for a description of all available options.

Contributions:

If you're interested in contributing to this project, first of all I would like to extend my heartfelt gratitude. I've written a small doc to describe how to get this running in a development setup.

https://github.com/dbcli/pgcli/blob/master/DEVELOP.rst

Please feel free to reach out to me if you need help. My email: [email protected], Twitter: @amjithr

Detailed Installation Instructions:

macOS:

The easiest way to install pgcli is using Homebrew.

$ brew install pgcli

Done!

Alternatively, you can install pgcli as a python package using a package manager called called pip. You will need postgres installed on your system for this to work.

In depth getting started guide for pip - https://pip.pypa.io/en/latest/installing.html.

$ which pip

If it is installed then you can do:

$ pip install pgcli

If that fails due to permission issues, you might need to run the command with sudo permissions.

$ sudo pip install pgcli

If pip is not installed check if easy_install is available on the system.

$ which easy_install

$ sudo easy_install pgcli

Linux:

In depth getting started guide for pip - https://pip.pypa.io/en/latest/installing.html.

Check if pip is already available in your system.

$ which pip

If it doesn't exist, use your linux package manager to install pip. This might look something like:

$ sudo apt-get install python-pip   # Debian, Ubuntu, Mint etc

or

$ sudo yum install python-pip  # RHEL, Centos, Fedora etc

pgcli requires python-dev, libpq-dev and libevent-dev packages. You can install these via your operating system package manager.

$ sudo apt-get install python-dev libpq-dev libevent-dev

or

$ sudo yum install python-devel postgresql-devel

Then you can install pgcli:

$ sudo pip install pgcli

Docker

Pgcli can be run from within Docker. This can be useful to try pgcli without installing it, or any dependencies, system-wide.

To build the image:

$ docker build -t pgcli .

To create a container from the image:

$ docker run --rm -ti pgcli pgcli <ARGS>

To access postgresql databases listening on localhost, make sure to run the docker in "host net mode". E.g. to access a database called "foo" on the postgresql server running on localhost:5432 (the standard port):

$ docker run --rm -ti --net host pgcli pgcli -h localhost foo

To connect to a locally running instance over a unix socket, bind the socket to the docker container:

$ docker run --rm -ti -v /var/run/postgres:/var/run/postgres pgcli pgcli foo

IPython

Pgcli can be run from within IPython console. When working on a query, it may be useful to drop into a pgcli session without leaving the IPython console, iterate on a query, then quit pgcli to find the query results in your IPython workspace.

Assuming you have IPython installed:

$ pip install ipython-sql

After that, run ipython and load the pgcli.magic extension:

$ ipython

In [1]: %load_ext pgcli.magic

Connect to a database and construct a query:

In [2]: %pgcli postgres://[email protected]:5432/world
Connected: [email protected]
[email protected]:world> select * from city c where countrycode = 'USA' and population > 1000000;
+------+--------------+---------------+--------------+--------------+
| id   | name         | countrycode   | district     | population   |
|------+--------------+---------------+--------------+--------------|
| 3793 | New York     | USA           | New York     | 8008278      |
| 3794 | Los Angeles  | USA           | California   | 3694820      |
| 3795 | Chicago      | USA           | Illinois     | 2896016      |
| 3796 | Houston      | USA           | Texas        | 1953631      |
| 3797 | Philadelphia | USA           | Pennsylvania | 1517550      |
| 3798 | Phoenix      | USA           | Arizona      | 1321045      |
| 3799 | San Diego    | USA           | California   | 1223400      |
| 3800 | Dallas       | USA           | Texas        | 1188580      |
| 3801 | San Antonio  | USA           | Texas        | 1144646      |
+------+--------------+---------------+--------------+--------------+
SELECT 9
Time: 0.003s

Exit out of pgcli session with Ctrl + D and find the query results:

[email protected]:world>
Goodbye!
9 rows affected.
Out[2]:
[(3793, u'New York', u'USA', u'New York', 8008278),
 (3794, u'Los Angeles', u'USA', u'California', 3694820),
 (3795, u'Chicago', u'USA', u'Illinois', 2896016),
 (3796, u'Houston', u'USA', u'Texas', 1953631),
 (3797, u'Philadelphia', u'USA', u'Pennsylvania', 1517550),
 (3798, u'Phoenix', u'USA', u'Arizona', 1321045),
 (3799, u'San Diego', u'USA', u'California', 1223400),
 (3800, u'Dallas', u'USA', u'Texas', 1188580),
 (3801, u'San Antonio', u'USA', u'Texas', 1144646)]

The results are available in special local variable _, and can be assigned to a variable of your choice:

In [3]: my_result = _

Pgcli only runs on Python3.6+ since 2.2.0, if you use an old version of Python, you should use install pgcli <= 2.2.0.

Thanks:

A special thanks to Jonathan Slenders for creating Python Prompt Toolkit, which is quite literally the backbone library, that made this app possible. Jonathan has also provided valuable feedback and support during the development of this app.

Click is used for command line option parsing and printing error messages.

Thanks to psycopg for providing a rock solid interface to Postgres database.

Thanks to all the beta testers and contributors for your time and patience. :)

Issues
  • Respect \pset pager on expected behavior

    Respect \pset pager on expected behavior

    \pset pager has three possible values: "always", "on", and "off". pgcli previously treated all non-"off" values as "always". This change implements the expected behavior, which is to use the pager when the output is larger than the terminal height (See \pset pager in https://www.postgresql.org/docs/9.2/static/app-psql.html). Pgcli adds to this and also uses the pager when the output is wider than the terminal width.

    Fixes #813

    Checklist

    • [x] I've added this contribution to the changelog.md.
    • [x] I've added my name to the AUTHORS file (or it's already there).
    opened by maxrothman 42
  • Make autocomplete schema-aware

    Make autocomplete schema-aware

    This PR would fix #22, and also I think #39 as a side-effect

    Issues:

    • I used pandas DataFrames for working with database metadata -- I found them a lot more flexible than a pure standard lib dict/list based approach. But I'm not sure how you'd feel about adding pandas as a requirement.
    • We don't have any tests for "DoubleQuoted" identifiers -- I'm not confident I didn't break that.
    opened by darikg 32
  • Amjith/specials refactor

    Amjith/specials refactor

    Reviewer: @darikg & @j-bennet

    This is a complete rewrite of the specials package. A few things have changed.

    1. pgspecial is now a directory with all the relevant files to make it into a standalone package.
    2. \c, \connect and use are now handled by pgspecial instead of pgexecute.py (which was always felt icky). We now pass in the PGExecute as db_obj to the specials package. The idea is that db_obj should have a connect() call which will be invoked to change the database. That way whoever decides to use the pgspecial can provide their own db_obj and still achieve the \c functionality.
    3. There are @export decorators sprinkled around the pgspecial code. The export decorator is defined in the __init__.py file. When a function is decorated by this @export it will be exposed by that package and available to use when that package is imported. It is a technique I picked up from David Beazly's tutorial at this PyCon 2015. http://www.dabeaz.com/modulepackage/index.html. Check the slides 53 to 56 on this pdf: http://www.dabeaz.com/modulepackage/ModulePackage.pdf for more details. BTW, that video is worth watching. :)

    I'm tagging both of you on this PR since you two have been the most active in that part of the code. I've ran through most of the special commands by hand to make sure I didn't break anything.

    Give it a whirl.

    opened by amjith 32
  • possible enhancing - using pspg for formatting

    possible enhancing - using pspg for formatting

    Description

    When I played with pgcli I had a opinion so formatting result is slow. Is possible to disable formatting in Python? pspg can read csv files now, and can format to tabular output.

    Your environment

    • [ ] Please provide your OS and version information.
    • [ ] Please provide your CLI version.
    • [ ] What is the output of pip freeze command.
    opened by okbob 32
  • [experimental] learn keyword preferences

    [experimental] learn keyword preferences

    Spinning this off from discussion in #377 since they're (mostly) orthogonal. I was originally a little skeptical of using any learning algorithm because

    1. It might be annoying to have different suggestions on different installations
    2. It might preclude improving the base suggestion engine. Right now sqlcomplete suggests only the very vague keyword category when it could take greater advantage of syntactical restrictions. Given SELECT * F, FREEZE is a pretty silly suggestion because it's just not valid sql.

    On the other hand, basing suggestions on syntax requires syntactically valid input, and a simple learning algorithm could be much more reliable in the middle of editing temporarily invalid queries. In the long run, the learning approach could move to estimating second- or third-order keyword transitions and be pretty powerful.

    So this PR offers a basic experiment of the learning approach. Measure zeroth-order keyword probabilities, and rank keywords thereby.

    Open questions:

    1. How should learning be shared between concurrent pgcli sessions? One global state or one state per pgcli instance?
    2. Should we (and if so, how do) we save keyword preferences between sessions?
    opened by darikg 30
  • Perform auto-completion refresh in background.

    Perform auto-completion refresh in background.

    @dbcli/vcli-core @dbcli/pgcli-core

    This is my first attempt at making the auto-completion refresh in a background thread. I tried it on a database with 40,000 tables in them and I can see a noticeable different in the startup time. I could get more granular by spawning a thread for each type of completion (eg: tables, views, columns etc), but that'll require some granular locking on data-structures.

    Since we get a tremendous speed boost with just one thread, I'm not motivated to do multiple threads.

    Please pitch in and let me know if there are better ways of doing this.

    opened by amjith 29
  • Cherry-picked prompt-toolkit 2.0 changes.

    Cherry-picked prompt-toolkit 2.0 changes.

    Changes for prompt-toolkit 2.0, based on current master.

    Cherry-picked from https://github.com/dbcli/pgcli/pull/826.

    @jonathanslenders I cherry-picked because I have no permissions to rebase your branch, but we can merge either PR, provided it's in line with current pgcli master.

    Problems noticed so far:

    • ~styles are not applied~ fixed
    • cli takes longer to start. I had to increase "show help" integration test timeout.
    • ~cli won't run under 2.7~ fixed, it was unicode literals
    • ~iocommands integration test fail on editor command~ fixed
    • ~named_queries integration test fail~ fixed

    Named query integration test failed because of this warning printed under pexpect (which is not a real terminal):

    https://github.com/jonathanslenders/python-prompt-toolkit/blob/b8d09e971e5fbad76d3c5bda4b47063e4c0644b8/prompt_toolkit/application/application.py#L706

    @jonathanslenders Is there a way to suppress this kind of error output for tests? perhaps is you use warnings vs writing to stdout?

    opened by j-bennet 29
  • Traceback on first run

    Traceback on first run

    Ubuntu 14.04, Python 2.7.3 (inside an activated virtualenv) pgcli==0.10.0 (installed inside activated virtualenv)

    I get the following...

    665 18:30:11 [~/code/ottoman] J:0 venv λ customcart ▼ pgcli ottoman
    Traceback (most recent call last):
      File "/home/vagrant/code/ottoman/venv/bin/pgcli", line 5, in <module>
        from pkg_resources import load_entry_point
      File "/home/vagrant/code/ottoman/venv/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 2603, in <module>
      File "/home/vagrant/code/ottoman/venv/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 666, in require
      File "/home/vagrant/code/ottoman/venv/local/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg/pkg_resources.py", line 565, in resolve
    pkg_resources.DistributionNotFound: Click
    668 18:31:29 [~/code/ottoman] J:0 venv λ customcart ▼ psql ottoman
    psql (9.3.5)
    Type "help" for help.
    
    ottoman=# \q
    
    bug 
    opened by treystout 24
  • Started working on integration tests.

    Started working on integration tests.

    Copy of PR #266.

    opened by j-bennet 24
  • Can't install pglci

    Can't install pglci

    Description

    I can't not install pgcli because missing #include <libpq-fe.h>. I install libpq-dev, conflict current libpq5 current. image (1) image

    Your environment

    • OS: Ubuntu 20.04 - focal
    • pip: 21.2.4
    • python: 3.9.7
    • pip freeze
    cffi==1.14.6
    cli-helpers==2.2.0
    click==8.0.1
    configobj==5.0.6
    cryptography==3.4.8
    greenlet==1.1.1
    importlib-resources==5.2.2
    msgpack==1.0.2
    mycli==1.24.1
    prompt-toolkit==3.0.20
    psycopg2-binary==2.9.1
    pyaes==1.6.1
    pycparser==2.20
    Pygments==2.10.0
    PyMySQL==1.0.2
    pynvim==0.4.3
    pyperclip==1.8.2
    python-dateutil==2.8.2
    pytzdata==2020.1
    Send2Trash==1.8.0
    six==1.16.0
    sqlparse==0.3.1
    tabulate==0.8.9
    wcwidth==0.2.5
    zipp==3.5.0
    
    opened by thevan96 2
  • passing sql via command line a la '-c' for psql?

    passing sql via command line a la '-c' for psql?

    Description

    I don't see a 'sql via the command ilne switch' option which is surprising. Just want to make sure I'm not missing anything. I've tried just appending sql to the end of a database connection and also using '-c', neither of which work.

    Your environment

    MacOS

    • [x] Please provide your OS and version information. 10.15.7
    • [x] Please provide your CLI version. 3.1.0
    • [ ] What is the output of pip freeze command.
    opened by jonassteinberg1 0
  • stripping comments

    stripping comments

    Hello,

    I am tagging queries and I was using pgcli to exec them, things like this:

    /* TEST123 TAGGING */ select 1
    

    it looks to me that pgcli does not send /* */ or -- comments to the backend. Is this the desired behaviour?

    opened by edoardoc 0
  • Re-run last query with bare `\watch`

    Re-run last query with bare `\watch`

    Description

    Like psql, allow a user to first execute a query, and then run \watch to re-run the query in a loop.

    The remaining parity folks were looking for in #544 will be handled by dbcli/pgspecial#120 , which is a non-breaking API change and should thus already be compatible with the latest version of pgcli.

    Closes #544

    Example:

    $ pgcli -h localhost -p 5432 -U pg db
    Server: PostgreSQL 11.9 (Debian 11.9-1.pgdg90+1)
    Version: 3.2.0
    Home: http://pgcli.com
    [email protected]:db> \watch 1
    \watch cannot be used with an empty query
    
    [email protected]:db> select 123;
    +------------+
    | ?column?   |
    |------------|
    | 123        |
    +------------+
    SELECT 1
    Time: 0.018s
    [email protected]:db> \watch
    +------------+
    | ?column?   |
    |------------|
    | 123        |
    +------------+
    SELECT 1
    Time: 0.012s
    Waiting for 2 seconds before repeating
    +------------+
    | ?column?   |
    |------------|
    | 123        |
    +------------+
    SELECT 1
    Time: 0.015s
    Waiting for 2 seconds before repeating
    ^C [email protected]:db> \watch 1
    +------------+
    | ?column?   |
    |------------|
    | 123        |
    +------------+
    SELECT 1
    Time: 0.013s
    Waiting for 1 seconds before repeating
    +------------+
    | ?column?   |
    |------------|
    | 123        |
    +------------+
    SELECT 1
    Time: 0.018s
    Waiting for 1 seconds before repeating
    ^C [email protected]:db>
    

    Checklist

    • [x] I've added this contribution to the changelog.rst.
    • [x] I've added my name to the AUTHORS file (or it's already there).
    • [x] I installed pre-commit hooks (pip install pre-commit && pre-commit install), and ran black on my code.
    • [x] Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)
    opened by saifelse 1
  • Broken RC file behaviours.

    Broken RC file behaviours.

    Description

    I've identified 2 broken behaviours (detailed below) pertaining to how RC files are handled.

    Scenario 1: in certain cases the RC file is moved

    The Setup:

    • write config to "~/.pgclirc"
    • "~/.pgpass" contains "[host]:[port]:*:[user]:[pass]"

    The Command:

    • /usr/bin/pgcli "postgres://[user]@[host]/[database]"

    The Outcome: Note I cannot verify exactly what order some of the below items occur in, as I can only attest to what order I see output generated in.

    • a "~/.config/pgcli" directory is created
    • the "~/.pgclirc" file is moved (this is not a copy-delete two-step, for whatever that's worth) to "~/.config/pgcli/config"
    • the following output is generated:
      Config file (\~/.pgclirc) moved to new location /home/nestor/.config/pgcli/config
      
    • the config file is properly read and parsed without issue
    • prompt

    The Problem:

    • the most superficial problem is that there is no reason for this whatsoever
    • the unnecessary and unexpected file move can break dotfile backup processes
    • pgcli will fail to start at all (with a PermissionError: [Errno 13]) if the process cannot create "~/.config/pgcli" or write to "~/.config/pgcli/config"

    The Expectation:

    • no directories are created
    • no files are moved
    • the config file is properly read and parsed without issue
    • prompt

    Scenario 2: in certain cases the RC file is moved and also replaced with the default config

    Thinking that explicitly setting the --pgclirc option might make it clear that "this is where my config file is and this is where you should read it from, do nothing else please and thank you", I found a related (but somehow worse) problem.

    The Setup:

    • write config to "~/.pgclirc"
    • "~/.pgpass" contains "[host]:[port]:*:[user]:[pass]"

    The Command:

    • /usr/bin/pgcli --pgclirc="\~/.pgclirc" "postgres://[user]@[host]/[database]"

    The Outcome: Note I cannot verify exactly what order some of the below items occur in, as I can only attest to what order I see output generated in.

    • a "~/.config/pgcli" directory is created
    • the "~/.pgclirc" file is moved (this is not a copy-delete two-step, for whatever that's worth) to "~/.config/pgcli/config"
    • the following output is generated:
      Config file (~/.pgclirc) moved to new location /home/nestor/.config/pgcli/config
      
    • the default config is written to "~/.pgclirc"
    • the default config (as written to "~/.pgclirc") is read and parsed
    • config-related errors are reported, depending on your system setup (e.g. no keyring backend is available but the default config attempts to read from a keyring)
    • prompt

    The Problem:

    • all of the problems mentioned in Scenario 1 are also at play here
    • this is a more insidious problem than in Scenario 1, however, as dotfile backup processes will now continue to work with the (newly-written) "~/.pgclirc" file, which no longer contains our config
    • now using the default config, pgcli will:
      • additionally write "~/.config/pgcli/log"
      • additionally write "~/.config/pgcli/history"
      • present a (potentially) incorrect prompt
      • potentially issue queries that adversely affect DB performance: e.g. You are a user who normally operates with multi_line = true and a low row_limit, and expect that entering ...
        SELECT [complex query with many function calls] FROM [large table or complex series of joins]
        WHERE ([condition on indexed field that VASTLY limits the resultset])
        

        ... will normally execute your query fairly quickly, but now the request is fired off to the DB on the first newline, before any WHERE is seen.

      • I have not verified this myself, but I expect if pgcli had been invoked with -D/--dsn, this would fail as the loaded config dose not contain your "[alias_dsn]" entries.

    The Expectation:

    • no directories are created
    • no files are moved
    • "~/.pgclirc" is not reset to the default config
    • the config file is properly read and parsed without issue
    • prompt

    Your Environment

    • [X] Please provide your OS and version information.

      uname -s -r -o yields:

      Linux 5.8.0-1038-gcp GNU/Linux
      

      lsb_release --all yields:

      No LSB modules are available.
      Distributor ID: Ubuntu
      Description:    Ubuntu 20.10
      Release:        20.10
      Codename:       groovy
      
    • [X] Please provide your CLI version.

      /usr/bin/pgcli --version yields:

      Version: 3.0.0
      

      (This is the newest available version in my distro's repos. I have verified none of the above behaviours are changed by any commit made between the v3.0.0 release and the v3.1.0 release.)

    • [X] What is the output of pip freeze command.

      pip freeze yields:

      attrs==19.3.0
      Automat==20.2.0
      blinker==1.4
      certifi==2020.4.5.1
      chardet==3.0.4
      click==7.1.2
      cloud-init==21.2
      colorama==0.4.3
      command-not-found==0.3
      configobj==5.0.6
      constantly==15.1.0
      cryptography==3.0
      dbus-python==1.2.16
      distro==1.5.0
      distro-info===0.23ubuntu1
      httplib2==0.18.1
      humanize==2.5.0
      hyperlink==19.0.0
      idna==2.10
      importlib-metadata==1.6.0
      incremental==16.10.1
      jeepney==0.4.3
      Jinja2==2.11.2
      jsonpatch==1.25
      jsonpointer==2.0
      jsonschema==3.2.0
      keyring==21.3.0
      language-selector==0.1
      launchpadlib==1.10.13
      lazr.restfulclient==0.14.2
      lazr.uri==1.0.5
      MarkupSafe==1.1.1
      more-itertools==4.2.0
      netifaces==0.10.4
      oauthlib==3.1.0
      pexpect==4.6.0
      pgspecial==1.11.10
      prompt-toolkit==3.0.6
      psycopg2==2.8.5
      pyasn1==0.4.8
      pyasn1-modules==0.2.1
      Pygments==2.3.1
      PyGObject==3.38.0
      PyHamcrest==1.9.0
      PyJWT==1.7.1
      PyMySQL==0.9.3
      pyOpenSSL==19.1.0
      pyrsistent==0.15.5
      pyserial==3.4
      python-apt==2.1.3+ubuntu1.4
      python-debian==0.1.37
      PyYAML==5.3.1
      requests==2.23.0
      requests-unixsocket==0.2.0
      SecretStorage==3.1.2
      service-identity==18.1.0
      setproctitle==1.1.10
      simplejson==3.17.0
      six==1.15.0
      sos==4.1
      sqlparse==0.3.1
      ssh-import-id==5.10
      systemd-python==234
      tabulate==0.8.6
      terminaltables==3.1.0
      Twisted==18.9.0
      ubuntu-advantage-tools==27.0
      ufw==0.36
      unattended-upgrades==0.1
      urllib3==1.25.9
      wadllib==1.3.4
      wcwidth==0.1.9
      zipp==1.0.0
      zope.interface==4.7.1
      

      (Note I'm not sure if the above is actually useful or not, as I did not install pgcli via pip.)

    opened by nestor-custodio 2
  • Feature request: Autocomplete suggestion for current date or datetime

    Feature request: Autocomplete suggestion for current date or datetime

    This is a feature request/ idea.

    I often verify queries on some arbitrary recent date or datetime. It would be neat if typing e.g. '2021- would autocomplete to the current date (e.g. '2021-08-11') or the current datetime. Or perhaps first the current date, then, if one continues (``'2021-08-11 `) autofill suggests the current datetime.

    I could probably implement this myself since I am familiar with python. However, I first wanted to ask whether such a feature even makes sense and of course if you are even interested in having someone "external" like me attempt this.

    opened by JohannHansing 0
  • add explain visualizer

    add explain visualizer

    Description

    adds a formatter for explain analyze output based on https://github.com/dkuku/pyev

    Checklist

    • [x] I've added this contribution to the changelog.rst.
    • [x] I've added my name to the AUTHORS file (or it's already there).
    • [x] I installed pre-commit hooks (pip install pre-commit && pre-commit install), and ran black on my code.
    • [x] Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)
    opened by dkuku 5
  • Backslash in pgcli using a Windows computer

    Backslash in pgcli using a Windows computer

    Description

    I didn't find out how to type a backslash in pgcli using my system (Windows 10, HP ZBook). Normally, I type: ctrl + alt + <. It does not work on my Windows machine.

    Your environment

    Windows 10, HP ZBook (Intel(R) Core(TM) i7-4910MQ CPU @ 2.90GHz , 32GB RAM).

    • Windows 10 Enterprise, Version: 20H2
    • pgcli Version 3.1.0
    opened by DataMower 1
  • pgcli is too slow to connect to the postgresql

    pgcli is too slow to connect to the postgresql

    Description

    pgcli is too slow to connect to the postgresql,while native psql client is not.

    ps: Mycli is just as fast as the native mysql client

    Your environment

    OS:Ubuntu 20.4 x64 postgresql:12.7 pgcli:3.1.0 ##my command

    pgcli -hlocalhost -Upostgres
    
    opened by weni09 0
  • Bad temp file handling

    Bad temp file handling

    Description

    1. invoke pgcli
    2. \l
    3. q
    4. crash:
    Traceback (most recent call last):
      File "C:\Python\3.8\lib\runpy.py", line 194, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "C:\Python\3.8\lib\runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "<redacted>\venv\Scripts\pgcli.exe\__main__.py", line 7, in <module>
      File "<redacted>\venv\lib\site-packages\click\core.py", line 1134, in __call__
        return self.main(*args, **kwargs)
      File "<redacted>\venv\lib\site-packages\click\core.py", line 1059, in main
        rv = self.invoke(ctx)
      File "<redacted>\venv\lib\site-packages\click\core.py", line 1401, in invoke
        return ctx.invoke(self.callback, **ctx.params)
      File "<redacted>\venv\lib\site-packages\click\core.py", line 767, in invoke
        return __callback(*args, **kwargs)
      File "<redacted>\venv\lib\site-packages\pgcli\main.py", line 1336, in cli
        pgcli.run_cli()
      File "<redacted>\venv\lib\site-packages\pgcli\main.py", line 765, in run_cli
        query = self.execute_command(text)
      File "<redacted>\venv\lib\site-packages\pgcli\main.py", line 684, in execute_command
        self.echo_via_pager("\n".join(output))
      File "<redacted>\venv\lib\site-packages\pgcli\main.py", line 1085, in echo_via_pager
        click.echo_via_pager(text, color=color)
      File "<redacted>\venv\lib\site-packages\click\termui.py", line 302, in echo_via_pager
        return pager(itertools.chain(text_generator, "\n"), color)
      File "<redacted>\venv\lib\site-packages\click\_termui_impl.py", line 357, in pager
        return _tempfilepager(generator, "more <", color)
      File "<redacted>\venv\lib\site-packages\click\_termui_impl.py", line 440, in _tempfilepager
        os.unlink(filename)
    PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: '%TEMP%\\tmp_cpxsj61'
    

    Happens 100% reliably.

    Your environment

    Windows 10 version 21H1 python 3.8.10 python packages (in a clean venv in which pgcli is the only package installed manually):

    cli-helpers==2.1.0
    click==8.0.0
    colorama==0.4.4
    configobj==5.0.6
    pendulum==2.1.2
    pgcli==3.1.0
    pgspecial==1.12.1
    prompt-toolkit==3.0.18
    psycopg2==2.8.6
    Pygments==2.9.0
    python-dateutil==2.8.1
    pytzdata==2020.1
    setproctitle==1.2.2
    six==1.16.0
    sqlparse==0.4.1
    tabulate==0.8.9
    terminaltables==3.1.0
    wcwidth==0.2.5
    
    windows 
    opened by olivier65 3
Owner
dbcli
Better CLIs for Databases
dbcli
 OS X command line tools for developers – The ultimate tool to manage your Mac. It provides a huge set of command line commands that automatize the usage of your OS X system.

Mac CLI  macOS command line tools for developers ⭐ Now with modularity and plugins! You can check the plugins folder: /mac-cli/plugins Contributions

Gabriel Guarino 8.1k Sep 21, 2021
A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.

mycli A command line client for MySQL that can do auto-completion and syntax highlighting. HomePage: http://mycli.net Documentation: http://mycli.net/

dbcli 9.9k Sep 19, 2021
GitHub’s official command line tool

GitHub CLI gh is GitHub on the command line. It brings pull requests, issues, and other GitHub concepts to the terminal next to where you are already

GitHub CLI 25.5k Sep 24, 2021
As easy as /aitch-tee-tee-pie/ 🥧 Modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins more. https://twitter.com/httpie

HTTPie: human-friendly CLI HTTP client for the API era HTTPie (pronounced aitch-tee-tee-pie) is a command-line HTTP client. Its goal is to make CLI in

null 52k Sep 15, 2021
Mac App Store command line interface

mas-cli A simple command line interface for the Mac App Store. Designed for scripting and automation. ?? Install ?? Homebrew Homebrew is the preferred

mas-cli 8.4k Sep 20, 2021
 Swiss Army Knife for macOS

 m-cli ?? Swiss Army Knife for macOS ! Overview Install Uninstall How To Use All Commands Contributing Overview m-cli is a macOS command line tool th

Roger 8.5k Sep 21, 2021
Move files and directories to the trash

Move files and folders to the trash Works on macOS (10.12+), Linux, and Windows (8+). Note: The Linux implementation is not very good and not maintain

Sindre Sorhus 2.2k Sep 15, 2021
A community Bash framework.

Bash-it is a collection of community Bash commands and scripts for Bash 3.2+. (And a shameless ripoff of oh-my-zsh ?? ) Includes autocompletion, theme

null 12.5k Sep 18, 2021
Colorizing `cat`

ccat ccat is the colorizing cat. It works similar to cat but displays content with syntax highlighting. Supported Languages JavaScript Java Ruby Pytho

Owen Ou 2.9k Sep 21, 2021
Tasks, boards notes for the command-line habitat

Taskbook Tasks, boards & notes for the command-line habitat Description By utilizing a simple and minimal usage syntax, that requires a flat learning

Klaus Sinani 8.2k Sep 18, 2021
cliclick is a macOS CLI tool for emulating mouse and keyboard events

cliclick (short for “Command Line Interface Click”) is a tool for executing mouse- and keyboard-related actions from the shell/Terminal. It is written in Objective-C and runs on OS X 10.15 or later.

Carsten Blüm 1.1k Sep 17, 2021
:rocket::star: A Zsh prompt for Astronauts

?? ⭐ Spaceship ZSH Zsh prompt for Astronauts. Website | Install | Features | Options | API Built with ❤︎ by Denys Dovhan and contributors Spaceship is

Denys Dovhan 15.2k Sep 16, 2021
Command-line tool that instantly fetches Stack Overflow results when an exception is thrown

rebound Rebound is a command-line tool that instantly fetches Stack Overflow results when an exception is thrown. Just use the rebound command to exec

Jonathan Shobrook 3.7k Sep 19, 2021
Control the macOS dark mode from the command-line

dark-mode Control the macOS dark mode from the command-line Requires macOS 10.10 or later. macOS 10.13 or earlier needs to download the Swift runtime

Sindre Sorhus 587 Sep 6, 2021
💡 CLI tool to input and store your ideas without leaving the terminal

eureka eureka is a CLI tool that allows you to quickly write down an idea using your preferred editor, and then have the idea committed and pushed to

Simon Egersand 391 Sep 19, 2021
Execute SQL against structured text like CSV or TSV

TextQL Allows you to easily execute SQL against structured text like CSV or TSV. Example session: Major changes! In the time since the initial release

Paul Bergeron 8.7k Sep 16, 2021
Find files with SQL-like queries

fselect Find files with SQL-like queries Why use fselect? While it doesn't tend to fully replace traditional find and ls, fselect has these nice featu

null 3k Sep 15, 2021
A new type of shell

README Nushell A new type of shell. Status This project has reached a minimum-viable product level of quality. While contributors dogfood it as their

Nushell Project 15.9k Sep 24, 2021
Git-integrated backup tool for macOS and Linux devs.

shallow-backup shallow-backup lets you easily create lightweight backups of installed packages, applications, fonts and dotfiles, and automatically pu

Aaron Lichtman 786 Sep 17, 2021