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

Closed
ajrcarey opened this issue Mar 23, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@ajrcarey
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">
<head>
    <title>NanoSQL Empty COUNT test</title>
    <meta charset="utf-8">
    <script src="https://cdn.jsdelivr.net/npm/@nano-sql/core@2.2.1/dist/nano-sql.min.js"></script>
</head>
<body>
</body>
<script>
    nSQL().connect({
        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(() => {
        nSQL('users')
            .query('select', ['COUNT(*) as count'])
            .exec()
            .then((rows) => { console.log(rows) });
    });
</script>
</html>

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.

@ClickSimply

This comment has been minimized.

Copy link
Owner

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.

@ajrcarey

This comment has been minimized.

Copy link
Author

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.