Normally, psql will do the hard work of formatting rows and columns of data in a monospaced font with the right amount of padding for everything to line up – within reason. One of the first helpful hints I learned early on with psql was that there are two modes for displaying both query and meta-command results. If there would be more than one match, psql will provide possible matches similar to a Linux terminal. If you want to list a table or connect to a different database, begin with the meta-command and then begin to type the object name and press TAB. For many commands, you can use the TAB key to trigger autocompletion or suggestion. If you don’t add a semicolon, psql will simply provide a new line for you to keep typing as shown below. In psql, you signal the end of a SQL statement by adding the semicolon and pressing enter. PostgreSQL adheres to the ANSI SQL standard which specifies the semicolon for statement termination. Knowing how to enable certain features or find help for each meta-command will go a long way in helping you to be a successful user of the tool. Any slash command ( \) is used to specify a meta-command that will typically run the necessary SQL queries in the background and return the results in a readable format.įirst, let’s look at a few tips about how psql works as a command line tool. The psql utility is packed with many helpful commands to help you explore and manage your database. To get the most value out of this content, you should have psql installed and connected to a PostgreSQL database so that you can try the commands as you read. From basic command syntax to the most common (and helpful) meta-commands, it’s all covered throughout the rest of the article. In this article we’ll get you up and running with all of the essential things you need to know to start on your journey to becoming a psql power-user. In our first article, we discussed the brief history of psql and demonstrated how to install it on your platform of choice and connect to a PostgreSQL database. Having access to the psql command-line tool is essential for any developers or DBAs that are actively working with and connecting to PostgreSQL databases.
0 Comments
Leave a Reply. |