-
Notifications
You must be signed in to change notification settings - Fork 3
Semantic difference in division operator (SQLite vs. MySQL) #2
Description
@Beliefuture Thank you for your hard work on this impactful project!
I have a quick question about semantic equivalence. If I understand correctly, the sqlite and mysql queries in the source-target query pair are intended to be equivalent?
I noticed a subtle semantic difference in the BIRD example. SQLite defaults to floor (integer) division for the / operator, while MySQL performs an implicit type conversion and returns a decimal, even though the operator is the same.
{
"norm": "SELECT SUM(identifier) / NULLIF(COUNT(identifier), 0) FROM identifier WHERE SUBSTRING(identifier, 'value', 'value') BETWEEN '''value''' AND '''value'''",
"sqlite": "SELECT SUM(height) / COUNT(id) FROM Player WHERE SUBSTR(birthday, 1, 4) BETWEEN '1990' AND '1995'",
"mysql": "SELECT SUM(height) / COUNT(id) FROM Player WHERE SUBSTRING(birthday, 1, 4) BETWEEN '1990' AND '1995'",
"id": "BIRD"
}
To illustrate, for the following minimal database instance:
CREATE TABLE Player (
id INT,
birthday VARCHAR(20),
height INT
);
INSERT INTO Player (id, birthday, height) VALUES (0, '1995', 150);
INSERT INTO Player (id, birthday, height) VALUES (1, '1990', 151);
SQLite returns 150 while MySQL returns 150.5.
For the queries to be semantically equivalent (matching SQLite's integer division), I believe the MySQL query would need to use the DIV operator: SELECT SUM(height) DIV COUNT(id) FROM ...
Is this behavior intended, or is this a case where the translation could be more precise? Thanks!