我正在进行一个flyway迁移,它将一个表的内容作为JSON字符串写入另一个表的字段中。我试图摆脱这些表中的大约50个,并用包含JSON字符串的字段替换它们。
我遇到的问题是,当我在MySQL Workbench中运行它时查询运行正常,但是当我运行flyway迁移时它失败了。我试过修改查询。运行一个非常简单的存储过程。在INFORMATION_SCHEMA.COLUMNS上运行选择也可以正常工作。我尝试使用SET @qry:=()编写查询,但没有区别。我对如何解决这个问题表示赞赏。
MySQLSyntaxErrorException: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version
for the right syntax to use near 'PREPARE stmt FROM @qry;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- =========' at line 13
这是查询
SET GLOBAL group_concat_max_len = (10*1024);
SET GLOBAL max_allowed_packet = (50*1024*1024);
SET @schema = 'db';
SET @table = 'InterfaceTable';
SET @className = 'TestInterfaceConfing';
SET @interfaceType = 'Test';
SELECT CONCAT(
'UPDATE TestTable as tt SET interfaceConfig=(SELECT CONCAT(TRIM(TRAILING ', QUOTE(','),
' FROM CONCAT(', QUOTE('{"@class":"'), ',', QUOTE(@className), ',', QUOTE('",'), ',',
GROUP_CONCAT(QUOTE('"'), ',', QUOTE(COLUMN_NAME), ',', QUOTE('"'), ',', QUOTE(':'), ',',
IF(type like '%CHAR', '\'"\',', ''), 'IF(', COLUMN_NAME, ' is null,', IF(type like '%CHAR', '\'\'', QUOTE('null')) , ',', COLUMN_NAME, ')', IF(type like '%CHAR', ',\'"\'', ''), ',', QUOTE(',')),
')), ''}'') FROM ', @table, ' as interface WHERE tt.id=interface.id) where tt.interfaceType=', QUOTE(@interfaceType), ';'
)
INTO @qry
FROM
(SELECT COLUMN_NAME, DATA_TYPE as type FROM INFORMATION_SCHEMA.COLUMNS c
WHERE TABLE_SCHEMA = @schema AND TABLE_NAME = @table) t;
PREPARE stmt FROM @qry;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
答案 0 :(得分:0)
这几乎可以肯定是由于我们的解析器因多种引号组合而跳闸。请在问题跟踪器中提交问题,并提供最简单的查询形式。
答案 1 :(得分:0)
我使用com.googlecode.flyway:flyway-core version:2.1.1
我不得不将1个长脚本分解为13个脚本的一部分。