Open the Project tool window ( View | Tool Windows | Project) and double-click an SQL file.įor more information about attaching directories and files in IntelliJ IDEA, refer to User files.Ĭlick the statement that you want to execute.Īlso, you can select (highlight) the fragment of code that you want to execute. When you open a file that is larger than 20 MB, you see only first 2.5 MB of the file. The limitation for the file size is 20 MB. In IntelliJ IDEA, you can open and run a file. The suggestion list always contains an item for running all the statements. If you have several statements, select whether you want to execute all statements or a single statement. Type or paste the statement that you want to execute.Ĭlick the Execute button ( ) on the toolbar. For more information about working with consoles, refer to Work with consoles. In the Database tool window ( View | Tool Windows | Database), click the data source. You can relate to a query console as to a terminal where you type and run your code. Run statements and procedures Run statements in a query console Type, press Control+Enter, and run your code.įor more information about where and how to view query results, refer to Query results. You can use a query console in the same way as you use a terminal. The only difference is that the query console is already connected to a data source, so you can type and run your code right away. Below we show a listing of objects in the database, first in the normal table mode and then with expanded mode turned on.A database or query console does not differ from other SQL files like user files and scratches. You can toggle expanded mode on and off by using the \x command. In this format you can page through results one at a time. In these cases, you can print the results in an “expanded” format which is essentially a crosstab of each row showing the column headings on the left and each value on the right. When terminal wrapping takes place, however, it can be challenging to figure out which data goes with which column. 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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |