Typing in the query buffer is similar to typing at a operating system command
prompt. However, at a operating system command prompt, Enter completes
each command. In psql, commands are completed only when you
enter a semicolon (;) or backslash-g (\g).
Here's a good example. Let's do SELECT 1 + 3; but in a different way.
See figure .4.2
Notice how the query is spread the over three lines. The semicolon was the
thing that told psql to send the query to the server. We could easily
have replaced the semicolon with backslash-g. I don't recommend you type
queries as ugly as this one, but longer queries will benefit from the ability
to spread them over multiple lines. You may notice that part of the query is
in uppercase, and some of it is in lowercase. Unless you are typing a string
in quotes, the POSTGRESQL server doesn't care whether words are uppercase
or lowercase. For stylistic reasons, I recommend words special to POSTGRESQL
be entered in all uppercase, and user-supplied words in lowercase.
Try some queries on your own involving arithmetic. Each computation must start
with the word SELECT, then your computation, and finally a semicolon
or backslash-g to finish. For example, SELECT 4 * 10; would
return 40. In psql, addition is plus (+), subtraction
is minus (-), multiplication is asterisk (*), and division
is forward slash (/).
If you have readline4.3 installed, 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 query strings.