-
Notifications
You must be signed in to change notification settings - Fork 54
Open
Description
On corrosion commit 85a0aed with the following sql schema
CREATE TABLE foo (
id INTEGER NOT NULL PRIMARY KEY
);
Templates using aggregation functions like sum
or json_group_array
render improperly
For ex. with the following rhai template
<%= sql("SELECT sum(foo.id) FROM foo").to_json(#{pretty: true}) %>
The result in an empty database looks like this
[
{
"sum(foo.id)": null
}
]
Then after inserting some values INSERT INTO foo(id) VALUES (1),(2),(3),(4);
the result is
[
{
"sum(foo.id)": null
},
{
"sum(foo.id)": 10
}
]
Then after INSERT INTO foo(id) VALUES (5);
the result is
[
{
"sum(foo.id)": null
},
{
"sum(foo.id)": 10
},
{
"sum(foo.id)": 5
}
]
While I would expect the template to render as
[
{
"sum(foo.id)": 15
}
]
The same issue is present when using json_group_array with the following template <%= sql("SELECT json_group_array(json_object('id', foo.id)) FROM foo").to_json(#{pretty: true}) %>
I would suggest to either disallow aggregations in the query parser or rerun the entire query when new data arrives.
Metadata
Metadata
Assignees
Labels
No labels