Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate COUNT function does not return a value on empty table #134

ajrcarey opened this issue Mar 23, 2019 · 2 comments


None yet
2 participants
Copy link

commented Mar 23, 2019

Using a pre-built minified 2.2.1 (the most recent version I could find), running a SELECT COUNT(*) operation does not return a value.

The following script creates an empty table, then runs a SELECT COUNT(*) query on that table:

<!DOCTYPE html>
<html lang="en">
    <title>NanoSQL Empty COUNT test</title>
    <meta charset="utf-8">
    <script src=""></script>
        id: 'test',
        mode: 'TEMP',
        tables: [
              name : 'users',
              model : {
                'id:uuid' : {'pk': true},
                'forename:string' : {},
                'surname:string' : {},
                'gender:string' : {},
                'age:int' : {},
                'education:string' : {},
                'occupation:string' : {},
                'salary:int' : {}
              indexes: {
                'forename:string' : {},
                'surname:string' : {},
                'age:int' : {},
                'gender:string' : {},
                'education:string' : {},
                'occupation:string' : {},
                'salary:int' : {}
    }).then(() => {
            .query('select', ['COUNT(*) as count'])
            .then((rows) => { console.log(rows) });

The expected result is ({count: 0}) or similar. Instead, a completely empty array is returned.

If this is the intended behaviour, perhaps the documentation could be updated to clarify, since this differs from standard SQL behaviour.


This comment has been minimized.

Copy link

commented Mar 24, 2019

Thanks so much for reporting this! 2.2.2 has just been released and should resolve everything!

I also added a test for this that runs against SQLite to make sure empty results of aggregate functions match against SQLite.


This comment has been minimized.

Copy link

commented Mar 25, 2019

Many thanks, I confirm the problem is resolved in 2.2.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.