我正在尝试执行查询。它正在抛出错误。
我有一个字典格式的值,我需要给它一个字符串供查询执行。即便是抛出错误。
以下是查询:
mysql> INSERT INTO wf_alti_scheduler_vijay (status,display_message,modified_on,exec_sequence,input_file_path,query_file_path,is_active,aws_destination_info,created_on,result_type,project,platform,scheduled_at,project_batch,frequency,output_file_path,env,next_schedule,kv_json,id,user) VALUES (-1.0,"test query","2016-10-24 13:15:35",1.0,"na","/home/viren/viru/workflow_dev/query/new_repeat_cust_current_month.sql",1.0,"na","2016-10-15 23:59:59","FILE","onyx_dev","HIVE","2016-10-15 23:59:59","onyx_monthly","monthly","/home/viren/viru/workflow_dev/op","dev","2016-11-15 23:59:59",{"QRY_PARAM_KEY_LIST": "PARAM_CURRENT_MONTH_START_DATE~PARAM_CURRENT_MONTH_END_DATE", "QRY_PARAM_VALUE_LIST": "20160901~20160930"},1.0,"virendhar");
ERROR 1054 (42S22): Unknown column {"QRY_PARAM_KEY_LIST": "PARAM_CURRENT_MONTH_START_DATE~PARAM_CURRENT_MONTH_END_DATE", "QRY_PARAM_VALUE_LIST": "20160901~20160930"} in 'field list'
除上述内容外,所有值均使用字符串格式。如何以字符串格式提供它来执行查询。有人可以为此提供帮助吗?
答案 0 :(得分:0)
每当某些json数据输入到值{"name":"kiran"}
之类的列时,请尝试输入为'{\"name\":\"kiran\"}'
。在您的情况下,数据
{"QRY_PARAM_KEY_LIST": "PARAM_CURRENT_MONTH_START_DATE~PARAM_CURRENT_MONTH_END_DATE", "QRY_PARAM_VALUE_LIST": "20160901~20160930"}
应输入为
'{\"QRY_PARAM_KEY_LIST\": \"PARAM_CURRENT_MONTH_START_DATE~PARAM_CURRENT_MONTH_END_DATE\", \"QRY_PARAM_VALUE_LIST\": \"20160901~20160930\"}'
尝试此查询
INSERT INTO wf_alti_scheduler_vijay (status,display_message,modified_on,exec_sequence,input_file_path,query_file_path,is_active,aws_destination_info,created_on,result_type,project,platform,scheduled_at,project_batch,frequency,output_file_path,env,next_schedule,kv_json,id,user) VALUES (-1.0,"test query","2016-10-24 13:15:35",1.0,"na","/home/viren/viru/workflow_dev/query/new_repeat_cust_current_month.sql",1.0,"na","2016-10-15 23:59:59","FILE","onyx_dev","HIVE","2016-10-15 23:59:59","onyx_monthly","monthly","/home/viren/viru/workflow_dev/op","dev","2016-11-15 23:59:59",'{\"QRY_PARAM_KEY_LIST\": \"PARAM_CURRENT_MONTH_START_DATE~PARAM_CURRENT_MONTH_END_DATE\", \"QRY_PARAM_VALUE_LIST\": \"20160901~20160930\"}',1.0,"virendhar")
如果您仍然收到任何错误,请检查您的表格结构,然后重试。
答案 1 :(得分:0)
MySQL 5.7.8支持本机JSON数据类型。因此,您可以将其用于上面的列。
还为json数据的开头和结尾添加('),如下所示:
INSERT INTO wf_alti_scheduler_vijay (status,display_message,modified_on,exec_sequence,input_file_path,query_file_path,is_active,aws_destination_info,created_on,result_type,project,platform,scheduled_at,project_batch,frequency,output_file_path,env,next_schedule,kv_json,id,user) VALUES (-1.0,"test query","2016-10-24 13:15:35",1.0,"na","/home/viren/viru/workflow_dev/query/new_repeat_cust_current_month.sql",1.0,"na","2016-10-15 23:59:59","FILE","onyx_dev","HIVE","2016-10-15 23:59:59","onyx_monthly","monthly","/home/viren/viru/workflow_dev/op","dev","2016-11-15 23:59:59",'{"QRY_PARAM_KEY_LIST": "PARAM_CURRENT_MONTH_START_DATE~PARAM_CURRENT_MONTH_END_DATE", "QRY_PARAM_VALUE_LIST": "20160901~20160930"}',1.0,"virendhar");
For Eg:INSERT INTO t1 VALUES('{"key1": "value1", "key2": "value2"}');