RequestFX
RequestFX
DTDrizzle Team
Created by RequestFX on 3/31/2024 in #help
How to query many-many with mysql
I setup a simple example to test if many-many query and ran again into the same issue.
Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(select coalesce(json_arrayagg(json_arrayps`.`user_id`, `u...' at line 1
at PromisePool.query (C:\Users\Anix\Documents\MyDocuments\Coding\JS\DrizzleTesting\node_modules\mysql2\promise.js:356:22)
at MySql2PreparedQuery.execute (C:\Users\Anix\Documents\MyDocuments\Coding\JS\DrizzleTesting\node_modules\src\mysql2\session.ts:88:31)
at QueryPromise.execute (C:\Users\Anix\Documents\MyDocuments\Coding\JS\DrizzleTesting\node_modules\src\mysql-core\query-builders\query.ts:149:25)
at QueryPromise.then (C:\Users\Anix\Documents\MyDocuments\Coding\JS\DrizzleTesting\node_modules\src\query-promise.ts:31:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ER_PARSE_ERROR',
errno: 1064,
sql: 'select `users`.`id`, `users`.`name`, `users_usersToGroups`.`data` as `usersToGroups` from `users` left join lateral (select coalesce(json_arrayagg(json_array(`users_usersToGroups`.`user_id`, `users_usersToGroups`.`group_id`, `users_usersToGroups_group`.`data`)), json_array()) as `data` from `users_to_groups` `users_usersToGroups` left join lateral (select json_array(`users_usersToGroups_group`.`id`, `users_usersToGroups_group`.`name`) as `data` from (select * from `groups` `users_usersToGroups_group` where `users_usersToGroups_group`.`id` =
`users_usersToGroups`.`group_id` limit 1) `users_usersToGroups_group`) `users_usersToGroups_group` on true where `users_usersToGroups`.`user_id` = `users`.`id`) `users_usersToGroups` on true',
sqlState: '42000',
near '(select coalesce(json_arrayagg(json_array(`users_usersToGroups`.`user_id`, `u...' at line 1"
}
Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(select coalesce(json_arrayagg(json_arrayps`.`user_id`, `u...' at line 1
at PromisePool.query (C:\Users\Anix\Documents\MyDocuments\Coding\JS\DrizzleTesting\node_modules\mysql2\promise.js:356:22)
at MySql2PreparedQuery.execute (C:\Users\Anix\Documents\MyDocuments\Coding\JS\DrizzleTesting\node_modules\src\mysql2\session.ts:88:31)
at QueryPromise.execute (C:\Users\Anix\Documents\MyDocuments\Coding\JS\DrizzleTesting\node_modules\src\mysql-core\query-builders\query.ts:149:25)
at QueryPromise.then (C:\Users\Anix\Documents\MyDocuments\Coding\JS\DrizzleTesting\node_modules\src\query-promise.ts:31:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ER_PARSE_ERROR',
errno: 1064,
sql: 'select `users`.`id`, `users`.`name`, `users_usersToGroups`.`data` as `usersToGroups` from `users` left join lateral (select coalesce(json_arrayagg(json_array(`users_usersToGroups`.`user_id`, `users_usersToGroups`.`group_id`, `users_usersToGroups_group`.`data`)), json_array()) as `data` from `users_to_groups` `users_usersToGroups` left join lateral (select json_array(`users_usersToGroups_group`.`id`, `users_usersToGroups_group`.`name`) as `data` from (select * from `groups` `users_usersToGroups_group` where `users_usersToGroups_group`.`id` =
`users_usersToGroups`.`group_id` limit 1) `users_usersToGroups_group`) `users_usersToGroups_group` on true where `users_usersToGroups`.`user_id` = `users`.`id`) `users_usersToGroups` on true',
sqlState: '42000',
near '(select coalesce(json_arrayagg(json_array(`users_usersToGroups`.`user_id`, `u...' at line 1"
}
6 replies