Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3b8ad00

Browse files
committed
Doc: sync src/tutorial/basics.source with SGML documentation.
basics.source is supposed to be pretty closely in step with the examples in chapter 2 of the tutorial, but I forgot to update it in commit f05a5e0. Fix that, and adjust a couple of other discrepancies that had crept in over time. (I notice that advanced.source is nowhere near being in sync with chapter 3, but I lack the ambition to do something about that right now.)
1 parent 2fb6154 commit 3b8ad00

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/tutorial/basics.source

+22-5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ SELECT *
7979
WHERE city = 'San Francisco'
8080
AND prcp > 0.0;
8181

82+
-- You can request that the results of a query be returned in sorted order:
83+
84+
SELECT * FROM weather
85+
ORDER BY city, temp_lo;
86+
8287
-- Here is a more complicated one. Duplicates are removed when DISTINCT is
8388
-- specified. ORDER BY specifies the column to sort on. (Just to make sure the
8489
-- following won't confuse you, DISTINCT and ORDER BY can be used separately.)
@@ -108,7 +113,8 @@ SELECT city, temp_lo, temp_hi, prcp, date, location
108113
-- table name. If you want to be clear, you can do the following. They give
109114
-- identical results, of course.
110115

111-
SELECT weather.city, weather.temp_lo, weather.temp_hi, weather.prcp, weather.date, cities.location
116+
SELECT weather.city, weather.temp_lo, weather.temp_hi,
117+
weather.prcp, weather.date, cities.location
112118
FROM weather JOIN cities ON weather.city = cities.name;
113119

114120
-- Old join syntax
@@ -125,8 +131,8 @@ SELECT *
125131
-- Suppose we want to find all the records that are in the temperature range
126132
-- of other records. w1 and w2 are aliases for weather.
127133

128-
SELECT w1.city, w1.temp_lo, w1.temp_hi,
129-
w2.city, w2.temp_lo, w2.temp_hi
134+
SELECT w1.city, w1.temp_lo AS low, w1.temp_hi AS high,
135+
w2.city, w2.temp_lo AS low, w2.temp_hi AS high
130136
FROM weather w1 JOIN weather w2
131137
ON w1.temp_lo < w2.temp_lo AND w1.temp_hi > w2.temp_hi;
132138

@@ -142,16 +148,27 @@ SELECT city FROM weather
142148
WHERE temp_lo = (SELECT max(temp_lo) FROM weather);
143149

144150
-- Aggregate with GROUP BY
145-
SELECT city, max(temp_lo)
151+
SELECT city, count(*), max(temp_lo)
146152
FROM weather
147153
GROUP BY city;
148154

149155
-- ... and HAVING
150-
SELECT city, max(temp_lo)
156+
SELECT city, count(*), max(temp_lo)
151157
FROM weather
152158
GROUP BY city
153159
HAVING max(temp_lo) < 40;
154160

161+
-- We can filter rows before aggregating them:
162+
SELECT city, count(*), max(temp_lo)
163+
FROM weather
164+
WHERE city LIKE 'S%'
165+
GROUP BY city;
166+
167+
-- Another way is the FILTER clause, which operates per-aggregate:
168+
SELECT city, count(*) FILTER (WHERE temp_lo < 45), max(temp_lo)
169+
FROM weather
170+
GROUP BY city;
171+
155172

156173
-----------------------------
157174
-- Updates:

0 commit comments

Comments
 (0)