![]() This was my take and experience of using the PGCLI tool and exploring the various features it provides that can be leveraged for quick interactions with a Postgres database. ![]() It saved a lot of time with auto-completion and integration with the text editor for writing longer queries, especially with JOINS and nested queries. I've personally used this tool in my current internship where I needed to create a few SQL queries to fetch particular data related to various tables and relationships. This tool is quite handy for people dealing with postgres databases and who need to view data or schema in that database. With the PSQL-like shell provided by the PGCLI tool, we were able to write SQL queries, execute commands, write/read queries from files, etc. In this little article, we were able to explore the basics of the PGCLI package in python, with that package we can interact with the Postgres database that can be on your local server or somewhere remotely. (without any filename) to stop appending the results to a file. We can achieve that with theĬommand, we need to specify the filename in which the output of the queries will be saved.Ĭommand, all the queries will start appending the results in the provided file. Let's say we have written a query inside the psql shell and we want the output to be saved in a file. In VI-normal mode, to open the current query in the default editor. We can even execute more than one query at a time if we use theĪt the end of each query. This will make us wait for the enter command for executing the query. We can write queries inside the editor and quit after we are done, once the editor is closed, the text is read from the editor and entered in the psql shell. Once, we have configured the editor, we will be inside the editor after we enter theĬommand. TheĮnvironment variable is preferred first. You can set them manually in the bashrc file by exporting the value ofĮnvironment variable as the name of the editor or the path to it. The default editor is chosen which will be set in one of yourĮnvironment variables. We can write a query from an editor by using theĬommand. We can use different editors for writing SQL queries. You can toggle the autocompletion with theĪs you would see in the bottom left corner of the shell. PGCLI shell has an auto-completion feature that will provide some suggestions based on the recent queries or commands executed or the default options. In normal mode where we will be prompted for the command executed in the same window. We can even execute shell commands by using the To delete the current line and enter into insert mode, Keybinding for movement and other normal mode keymaps likeįor moving a word in the backward direction, Though it's nice that PGCLI offers a VI-mode, it is great for people using Vim, when using the Shell for editing a Query, this mode can be utilized. Is just a normal typing experience without any modes or shortcut macros and other stuff. We can use two modes in PGCLI prompt, one is the Emacs mode which is the default one and the other is Vi-mode for Vim fanboys. We can even useįor moving vertically in an output table. We get an excellent table display of output which we can view by scroll or arrow keys. , it just works well and you don't have to install it every time or mess up your global python packages environment. There are a lot of ways pgcli can be installed, my preferred way is with The package acts as a CLI for accessing and executing any SQL queries, so we can simply provide the options/parameters to plug the database in and access the schema and its related data. PGCLI allows us to interact with any Postgres database via the command line, it can be a remote database or a local database, you can access it right away from your terminal. PGCLi is a python package that acts as a CLI for executing SQL queries in a Postgres database. This article will cover the basics of using the PGCLI tool to perform simply as well as advanced options in interacting with your Postgres database. If you are like CLIs and love to play with backend systems like Postgres(database) then chances are you will love this article. We can simply execute SQL queries in a PSQL-like shell with additional features like autocompletion, text-editing modes, file input/output options, etc. It's PGCLI, that can act as an editor window for writing SQL queries for Postgres Databases. ![]() Have you ever used the Postgres database and did you know you don't have to launch PGAdmin every time you want to write SQL queries, you can write down those queries even inside a terminal with a python package.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |