You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MySQL WHERE clause column qualification fails when the column is on the right side of a comparison operator. This causes the query to be generated incorrectly as the table alias is not properly added to the column name.
For example, with the WHERE clause 100 > user_id, the generated query incorrectly shows:
WHERE100> user_id
Instead of the correct:
WHERE100>t_09a0eed1cbbe07ca.user_id
This only affects MySQL queries. PostgreSQL queries work correctly regardless of column position.
How to reproduce
Use MySQL driver with a query having a WHERE clause
Put the column name on the right side of comparison (e.g., 100 > user_id)
Run the query builder
Observe that the generated query has unqualified column name
Minimal reproduction test:
funcTest_BuildQuery_MySQLColumnQualification(t*testing.T) {
t.Run("mysql column on right", func(t*testing.T) {
assert.Equal(t,
"SELECT `orders`.`order_id`, `orders`.`user_id` FROM `public`.`orders` AS `orders` INNER JOIN `public`.`users` AS `t_09a0eed1cbbe07ca` ON (`t_09a0eed1cbbe07ca`.`user_id` = `orders`.`user_id`) WHERE 100 > t_09a0eed1cbbe07ca.user_id ORDER BY `orders`.`order_id` ASC",
buildOrdersUsersSubsettingQuery(t, "100 > user_id", sqlmanager_shared.MysqlDriver),
)
})
}
Environment
MySQL driver
Go version: latest
OS: any
Additional context
Only affects MySQL queries
Only happens when column is on right side of comparison
PostgreSQL queries work correctly in all cases due to different AST traversal approach
The text was updated successfully, but these errors were encountered:
Bug description
MySQL WHERE clause column qualification fails when the column is on the right side of a comparison operator. This causes the query to be generated incorrectly as the table alias is not properly added to the column name.
For example, with the WHERE clause
100 > user_id
, the generated query incorrectly shows:Instead of the correct:
This only affects MySQL queries. PostgreSQL queries work correctly regardless of column position.
How to reproduce
100 > user_id
)Minimal reproduction test:
Environment
Additional context
The text was updated successfully, but these errors were encountered: