CreateAggregate state is shared, breaking multiple use of an aggregate function in the same query
See original GitHub issueusing SqliteConnection connection = new SqliteConnection(new SqliteConnectionStringBuilder
{
DataSource = "A",
Mode = SqliteOpenMode.Memory
}.ToString());
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = "CREATE TABLE [test](a, b, c);";
command.ExecuteNonQuery();
command.CommandText = "INSERT INTO [test](a, b, c) VALUES(1, 2, 3)";
command.ExecuteNonQuery();
command.ExecuteNonQuery();
}
connection.CreateAggregate(
"testCount",
new AggClass(),
(AggClass agg, int number) =>
{
agg.Counter++;
return agg;
},
agg => agg.Counter);
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT testCount(a), testCount(b), count(a), count(b) FROM [test];";
using var reader = command.ExecuteReader();
reader.Read();
Console.WriteLine((reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetInt32(3))); // (4, 4, 2, 2)
}
Microsoft.Data.Sqlite version: 5.0.10 Target framework: (e.g. .NET 5.0) .NET 5.0 Operating system: Windows 10 / MacOS 11.5.2
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to Combine Two Aggregate Functions in SQL
Learn how to combine two aggregate functions in one SQL query by using a subquery or a Common Table Expression (CTE).
Read more >Learn SQL: Aggregate Functions
Aggregate functions are a very powerful tool in databases. They serve the same purpose as their equivalents in MS Excel.
Read more >Overview of Aggregate Functions
An aggregate function performs a task in relation to one or more values from a single column and returns a single value. The...
Read more >Understanding the SQL SUM() function and its use cases
Today, I will describe the SQL SUM () function along with its use cases in this article. There are various mathematical calculations we...
Read more >Aggregate and Group Data to a Different Grain
You can use the following aggregate functions on measure columns: sum, unique, avg, count, max, and min. To prevent double counting, exclude aggregated...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It doesn’t work with struct.
as a workaround I’m using something like this
@pimbrouwers https://github.com/dotnet/efcore/issues/26070#issuecomment-926817699 gives a sketch of the solution if you’re interested in giving it a go.