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

Commit 8b6b414

Browse files
committed
Update pltcl regress test to exercise return_null; also make use of
the fact that CREATE FUNCTION and CREATE AGGREGATE now allow array types to be named like int4[] rather than _int4.
1 parent 179b8e5 commit 8b6b414

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/pl/tcl/test/runtest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ psql -q -n -e $DBNAME <test_queries.sql > test.out 2>&1
2121
if diff test.expected test.out >/dev/null 2>&1 ; then
2222
echo " Tests passed O.K."
2323
else
24-
echo " Tests faild - look at diffs between"
24+
echo " Tests failed - look at diffs between"
2525
echo " test.expected and test.out"
2626
fi
2727

src/pl/tcl/test/test.expected

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ select tcl_sum(key1) from T_pkey2;
133133
(1 row)
134134

135135
select tcl_avg(key1) from T_pkey1 where key1 = 99;
136-
ERROR: pltcl: divide by zero
136+
tcl_avg
137+
---------
138+
139+
(1 row)
140+
137141
select tcl_sum(key1) from T_pkey1 where key1 = 99;
138142
tcl_sum
139143
---------

src/pl/tcl/test/test_setup.sql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,22 +389,23 @@ create function tcl_int4add(int4,int4) returns int4 as '
389389
-- We use split(n) as a quick-and-dirty way of parsing the input array
390390
-- value, which comes in as a string like '{1,2}'. There are better ways...
391391

392-
create function tcl_int4_accum(_int4,int4) returns _int4 as '
392+
create function tcl_int4_accum(int4[], int4) returns int4[] as '
393393
set state [split $1 "{,}"]
394394
set newsum [expr {[lindex $state 1] + $2}]
395395
set newcnt [expr {[lindex $state 2] + 1}]
396396
return "{$newsum,$newcnt}"
397397
' language 'pltcl';
398398

399-
create function tcl_int4_avg(_int4) returns int4 as '
399+
create function tcl_int4_avg(int4[]) returns int4 as '
400400
set state [split $1 "{,}"]
401+
if {[lindex $state 2] == 0} { return_null }
401402
return [expr {[lindex $state 1] / [lindex $state 2]}]
402403
' language 'pltcl';
403404

404405
create aggregate tcl_avg (
405406
sfunc = tcl_int4_accum,
406407
basetype = int4,
407-
stype = _int4,
408+
stype = int4[],
408409
finalfunc = tcl_int4_avg,
409410
initcond = '{0,0}'
410411
);
@@ -413,7 +414,7 @@ create aggregate tcl_sum (
413414
sfunc = tcl_int4add,
414415
basetype = int4,
415416
stype = int4,
416-
initcond1 = '0'
417+
initcond1 = 0
417418
);
418419

419420
create function tcl_int4lt(int4,int4) returns bool as '

0 commit comments

Comments
 (0)