Navicat FUNCTION xxxx.JSON_ARRAYAGG does not exist.的一个大坑

123 阅读1分钟

今天使用Navicat工具进行sql查询时,使用了JSON.ARRAYAGG()聚合函数,但是执行的时候报错

[SQL]SELECT
	students.id AS id,
	students. NAME AS NAME,
	JSON_ARRAYAGG (
		JSON_OBJECT (
			'id',
			course.id,
			'name',
			course. NAME,
			'score',
			course.score
		)
	) AS xx
FROM
	`students`
LEFT JOIN `relation_student_course` AS re ON re.studentid = students.id
LEFT JOIN `course` ON course.id = re.courseid
WHERE
	course.id IS NOT NULL
GROUP BY
	students.id;
[Err] 1630 - FUNCTION music_db.JSON_ARRAYAGG does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual

我认真的检查了我的代码,并没有发现什么错误。最后发现是因为Navicat的“美化SQL”工具在美化代码的时候把JSON_ARRAYAGG后面添加了一个空格,变成了"JSON_ARRAYAGG ()",正是因为函数名和括号之间多出来的这个空格导致语句运行时出错,害我折腾了3个小时。