diff options
| author | Tom Lane | 2000-07-17 03:05:41 +0000 |
|---|---|---|
| committer | Tom Lane | 2000-07-17 03:05:41 +0000 |
| commit | bec98a31c55a4f799b398d01541e68d7c086bb81 (patch) | |
| tree | 14924bb5da2bc0a0f9bfac1aa5b32256fd996b9c /src/pl | |
| parent | 139f19c30221968e7d3bf64fe303cb41517e4601 (diff) | |
Revise aggregate functions per earlier discussions in pghackers.
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...
Diffstat (limited to 'src/pl')
| -rw-r--r-- | src/pl/tcl/test/test_setup.sql | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/pl/tcl/test/test_setup.sql b/src/pl/tcl/test/test_setup.sql index fe71584e1a1..7faabc12961 100644 --- a/src/pl/tcl/test/test_setup.sql +++ b/src/pl/tcl/test/test_setup.sql @@ -386,28 +386,33 @@ create function tcl_int4add(int4,int4) returns int4 as ' return [expr $1 + $2] ' language 'pltcl'; -create function tcl_int4div(int4,int4) returns int4 as ' - return [expr $1 / $2] +-- We use split(n) as a quick-and-dirty way of parsing the input array +-- value, which comes in as a string like '{1,2}'. There are better ways... + +create function tcl_int4_accum(_int4,int4) returns _int4 as ' + set state [split $1 "{,}"] + set newsum [expr {[lindex $state 1] + $2}] + set newcnt [expr {[lindex $state 2] + 1}] + return "{$newsum,$newcnt}" ' language 'pltcl'; -create function tcl_int4inc(int4) returns int4 as ' - return [expr $1 + 1] +create function tcl_int4_avg(_int4) returns int4 as ' + set state [split $1 "{,}"] + return [expr {[lindex $state 1] / [lindex $state 2]}] ' language 'pltcl'; create aggregate tcl_avg ( - sfunc1 = tcl_int4add, + sfunc = tcl_int4_accum, basetype = int4, - stype1 = int4, - sfunc2 = tcl_int4inc, - stype2 = int4, - finalfunc = tcl_int4div, - initcond2 = '0' + stype = _int4, + finalfunc = tcl_int4_avg, + initcond = '{0,0}' ); create aggregate tcl_sum ( - sfunc1 = tcl_int4add, + sfunc = tcl_int4add, basetype = int4, - stype1 = int4, + stype = int4, initcond1 = '0' ); |
