Commit 8b6e5e53 authored by cznic's avatar cznic

Accept * as an argument to count().

parent 11c02056
......@@ -14,6 +14,9 @@
//
// Change list
//
// 2015-06-15: To improve compatibility with other SQL implementations, the
// count built-in aggregate function now accepts * as its argument.
//
// 2015-05-29: The execution planner was rewritten from scratch. It should use
// indices in all places where they were used before plus in some additional
// situations. It is possible to investigate the plan using the newly added
......@@ -665,7 +668,7 @@
// | PrimaryExpression Slice
// | PrimaryExpression Call .
//
// Call = "(" [ ExpressionList ] ")" .
// Call = "(" [ "*" | ExpressionList ] ")" . // * only in count(*).
// Index = "[" Expression "]" .
// Slice = "[" [ Expression ] ":" [ Expression ] "]" .
//
......@@ -2062,12 +2065,15 @@
// returns 0 for an empty record set.
//
// func count() int // The number of rows in a record set.
// func count(*) int // Equivalent to count().
// func count(e expression) int // The number of cases where the expression value is not NULL.
//
// For example
//
// SELECT count() FROM department; // # of rows
//
// SELECT count(*) FROM department; // # of rows
//
// SELECT count(DepartmentID) FROM department; // # of records with non NULL field DepartmentID
//
// SELECT count()-count(DepartmentID) FROM department; // # of records with NULL field DepartmentID
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -260,6 +260,10 @@ Call:
{
$$ = $2
}
| '(' '*' ')'
{
$<item>$ = '*'
}
Call1:
/* EMPTY */
......@@ -831,6 +835,15 @@ PrimaryExpression:
return 1
}
if r, ok := $2.(rune); ok {
if f.isQualified() || f.s != "count" || r != '*' {
x.err(fmt.Sprintf("invalid expression %s(%c)", f, r))
return 1
}
$2 = []expression(nil)
}
var err error
var agg bool
if $$, agg, err = newCall(f.s, $2.([]expression)); err != nil {
......
......@@ -63,7 +63,7 @@ AlterTableStmt = "ALTER" "TABLE" TableName (
Assignment = ColumnName "=" Expression .
AssignmentList = Assignment { "," Assignment } [ "," ] .
BeginTransactionStmt = "BEGIN" "TRANSACTION" .
Call = "(" [ ExpressionList ] ")" .
Call = "(" [ "*" | ExpressionList ] ")" .
ColumnDef = ColumnName Type [
"NOT" "NULL"
| Expression
......
This diff is collapsed.
......@@ -8353,3 +8353,30 @@ SELECT * FROM t;
┌Iterate all rows of table "t"
└Output field names ["t"]
---- 1340
SELECT count() FROM t;
┌Iterate all rows of table "t"
└Output field names ["t"]
┌Group by distinct rows
└Output field names ["t"]
┌Evaluate count() as "",
└Output field names [""]
---- 1341
SELECT count() FROM t;
┌Iterate all rows of table "t"
└Output field names ["i"]
┌Group by distinct rows
└Output field names ["i"]
┌Evaluate count() as "",
└Output field names [""]
---- 1342
SELECT count() FROM t;
┌Iterate all rows of table "t"
└Output field names ["i"]
┌Group by distinct rows
└Output field names ["i"]
┌Evaluate count() as "",
└Output field names [""]
......@@ -15591,3 +15591,43 @@ COMMIT;
SELECT * FROM t;
|"t"
[2015-06-11 11:07:50 +0000 UTC]
-- 1338
BEGIN TRANSACTION;
CREATE TABLE t (t time);
COMMIT;
SELECT len(*) FROM t;
||invalid expression
-- 1339
BEGIN TRANSACTION;
CREATE TABLE t (t time);
COMMIT;
SELECT t.count(*) FROM t;
||invalid expression
-- 1339
BEGIN TRANSACTION;
CREATE TABLE t (t time);
COMMIT;
SELECT count(*) FROM t;
|""
[0]
-- 1340
BEGIN TRANSACTION;
CREATE TABLE t (i int);
INSERT INTO t VALUES (1), (NULL), (3);
COMMIT;
SELECT count(*) FROM t;
|""
[3]
-- 1341
BEGIN TRANSACTION;
CREATE TABLE t (i int);
INSERT INTO t VALUES (1), (NULL), (3);
COMMIT;
SELECT count() FROM t;
|""
[3]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment