mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-19 12:56:59 +08:00
There's now only one transition value and transition function. NULL handling in aggregates is a lot cleaner. Also, use Numeric accumulators instead of integer accumulators for sum/avg on integer datatypes --- this avoids overflow at the cost of being a little slower. Implement VARIANCE() and STDDEV() aggregates in the standard backend. Also, enable new LIKE selectivity estimators by default. Unrelated change, but as long as I had to force initdb anyway...
50 lines
1.0 KiB
SQL
50 lines
1.0 KiB
SQL
--
|
|
-- AGGREGATES
|
|
--
|
|
|
|
SELECT avg(four) AS avg_1 FROM onek;
|
|
|
|
SELECT avg(a) AS avg_32 FROM aggtest WHERE a < 100;
|
|
|
|
-- In 7.1, avg(float4) is computed using float8 arithmetic.
|
|
-- Round the result to 3 digits to avoid platform-specific results.
|
|
|
|
SELECT avg(b)::numeric(10,3) AS avg_107_943 FROM aggtest;
|
|
|
|
SELECT avg(gpa) AS avg_3_4 FROM ONLY student;
|
|
|
|
|
|
SELECT sum(four) AS sum_1500 FROM onek;
|
|
|
|
SELECT sum(a) AS sum_198 FROM aggtest;
|
|
|
|
SELECT sum(b) AS avg_431_773 FROM aggtest;
|
|
|
|
SELECT sum(gpa) AS avg_6_8 FROM ONLY student;
|
|
|
|
|
|
SELECT max(four) AS max_3 FROM onek;
|
|
|
|
SELECT max(a) AS max_100 FROM aggtest;
|
|
|
|
SELECT max(aggtest.b) AS max_324_78 FROM aggtest;
|
|
|
|
SELECT max(student.gpa) AS max_3_7 FROM student;
|
|
|
|
|
|
SELECT count(four) AS cnt_1000 FROM onek;
|
|
|
|
SELECT count(DISTINCT four) AS cnt_4 FROM onek;
|
|
|
|
select ten, count(*), sum(four) from onek group by ten;
|
|
|
|
select ten, count(four), sum(DISTINCT four) from onek group by ten;
|
|
|
|
|
|
SELECT newavg(four) AS avg_1 FROM onek;
|
|
|
|
SELECT newsum(four) AS sum_1500 FROM onek;
|
|
|
|
SELECT newcnt(four) AS cnt_1000 FROM onek;
|
|
|