Скачать в pdf «PostgreSQL»

Try some queries on your own involving arithmetic. Each computation must start with the word SELECT, then your computation, and finally a semicolon or baekslash-g. For example, SELECT 4 * 10; would return 40. Addition is performed using a plus symbol (+), subtraction using a minus symbol (-), multiplication using an asterisk (*), and division using a forward slash (/).

If you have readline3installed, psql will even allow you to use your arrow keys. Your left and right arrow keys allow you to move around, and the up and down arrows retrieve previously typed queries.

Displaying the Query Buffer

You can continue typing indefinitely, until you use a semicolon or baekslash-g. Everything you type will be buffered by psql until you are ready to send the query. If you use baekslash-p (p), you will see everything accumulated in the query buffer. In Figure
2.4, three lines of text are accumulated and displayed by the user using baekslash-p. After display, we use baekslash-g to execute the query, which returns the value 21. This ability comes in handy with long queries.

Erasing the Query Buffer

If you do not like what you have typed, use baekslash-r (r) to reset or erase the buffer.

2.3    Getting Help

You might ask, “Are these backslash commands documented anywhere?” If you look at Figure 2.1, you will see that the answer is printed every time psql starts. Backslash-? (?) prints all valid backslash commands. Backslash-h displays help for SQL commands. Sql commands are covered in the next chapter.

Скачать в pdf «PostgreSQL»