Web hosting packages - 618 CHAPTER 27 THE MANY POSTGRESQL CLIENTS

618 CHAPTER 27 THE MANY POSTGRESQL CLIENTS To learn more about a particular command, execute h again, but this time pass the command as a parameter. For example, to learn more about the INSERT command, execute the following: corporate=> h INSERT This produces the following output: Command: INSERT Description: create new rows in a table Syntax: INSERT INTO table [ ( column [, …] ) ] { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, …] ) | query } Therefore, h is useful not only for determining what psql commands are at your disposal, but also for recalling what syntax is required for a particular command. Executing a Query Once connected to a PostgreSQL server, you re free to execute any supported query. For example, to retrieve a list of all company employees, execute a SELECT query, like so: corporate=>SELECT lastname, email, telephone FROM employee ORDER by lastname; Executing a DELETE query works just the same: corporate=> DELETE FROM hr.employee WHERE lastname=’Gilmore’; If you re interested in executing a single query, you can do so when invoking psql, like so: %>psql -d corporate -U hrstaff -c “SELECT lastname, email, telephone FROM employee ORDER by lastname” Once the appropriate query result has been displayed, psql exits and returns to the command line. For automation purposes, you can dump query output to a file with the -o option: %>psql -d corporate -U hrstaff -c “SELECT lastname, email, telephone FROM employee ORDER by lastname” -o “/dataimport/employeeinfo.txt” Note In the next chapter, you ll learn how to execute commonplace administration tasks such as managing users and creating and destroying databases and schemas. Modifying the psql Prompt Because of the lack of visual cues when using the command line, it s easy to forget which database you re presently using, or even which server you re logged into if you re working on
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Leave a Reply