You might have noticed the text that
appears at the top of each column in the SELECT output--the
column label. The label usually is the name of the selected
column. However, you can control the text that appears at the top
of each column by using the AS keyword. For example, Figure
replaces the default column label firstname with the column
label buddy.
test=> SELECT firstname AS buddy FROM friend ORDER BY buddy;
buddy
-----------------
Cindy
Jack
Mark
Mike
Sam
(5 rows)
You might have noticed that the query in Figure
on page
has the column label ?column?.
The database server returns this label when there is no suitable label.
In that case, the result of an addition does not have an appropriate
label. Figure
shows the
same query with an appropriate label added using AS.
test=> SELECT 1 + 3 AS total;
total
-------
4
(1 row)