As described in the preceding section, each sequential element of a SQL statement is considered a token. What may
not be immediately clear, however, is that tokens may be kept all on the same line, or they may be split across several
lines, as extra whitespace is ignored by PostgreSQL's parser.
Consider the SQL statement in Example 3-1, which is executed first on a single line, and then
executed again, split across two separate lines. Both SELECT statements instruct the
database to display the entire contents of the my_list table:
Example 3-1. Spaces and newlines
testdb=#
SELECT * FROM my_list;
todos
------------------------------------------------
Pick up laundry.
Send out bills.
Wrap up Grand Unifying Theory for publication.
(3 rows)
testdb=#
SELECT *
testdb-#
FROM
testdb-#
my_list;
todos
------------------------------------------------
Pick up laundry.
Send out bills.
Wrap up Grand Unifying Theory for publication.
(3 rows)
In Example 3-1 there are several
newlines and spaces between the second statement's tokens. As you
can see by the identical output, PostgreSQL ignores the extra
newlines and spaces, making both statements semantically equivalent.
You can take advantage of this behavior by splitting a long string
of tokens across numerous lines for improved readability of your SQL
statement. This probably isn't necessary for statements as simple
as those in Example 3-1, but it can be quite
helpful when dealing with complex SQL statements with numerous
clauses, expressions, and conditions. Throughout this book we will
periodically split some statements over several lines to help show
what each part of the statement is intended to accomplish.