614 CHAPTER 27 THE MANY (Web host) POSTGRESQL CLIENTS

614 CHAPTER 27 THE MANY POSTGRESQL CLIENTS does a great job of succinctly defining each command, this section highlights just a few of the commands that you might find particularly useful. Further, many of the commands pertinent to the review of existing databases, schemas, tables, and users are introduced in the coming chapters. Note psql s tab-completion feature can save you a great deal of typing when executing commands. As you work through the following examples, tap the Tab key on occasion to review its behavior. Connecting to a New Database Over the course of a given session, you ll often need to work with more than one database. To change to a database named vendor, execute the following command: corporate=> connect vendor You can save a few keystrokes by using the abbreviated version of this command, c. Executing Commands Located Within a Specific File Repeatedly entering a predetermined set of commands can quickly become tedious, not to mention error-prone. Save yourself from such repetition by storing the commands within a separate file and then executing those commands by invoking the i command and passing along the name of the file, like so: corporate=> i audit.sql Editing a File Without Leaving psql If you are relying on commands found in a separate file, the task of repeatedly executing the command and then exiting psql to make adjustments to those commands from within an editor can become quite tedious. To save yourself from the tedium, you can edit these files without ever leaving psql by executing e. For example, to edit the audit.sql file used in the previous example, execute the following command: corporate=> e audit.sql This will open the file within whatever editor has been assigned via the PSQL_EDITOR variable (see Table 27-2 for more information about this variable). Once you ve completed editing the file, save the file using the editor s specific save command and exit the editor (:wq in vim, for instance). You will be returned directly back to the psql interface, and can again execute the file using i if you wish. Sending Query Output to an External File Sometimes you may wish to redirect query output to an external file for later examination or additional processing. To do so, execute the o command, passing it the name of the desired output file. For instance, to redirect all output to a file named output.sql, execute the o command, like so: corporate=> o output.sql
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Leave a Reply