如果以字符串形式包含json文档,如何在MySQL(5.6)列中设置值

时间:2019-01-22 15:52:58

标签: mysql json

如果其中包含JSON文档作为字符串,如何在MySQL(5.6)列中设置值

例如,如果我们有一个表-用户,那么我们有3列id,name和jsonConfig列,而jsonConfig列包含作为JSON文档的数据

{"key1":"val1","key2":"val2","key3":"val3"}

我想将jsonConfig列的val1的值替换为val4

我们可以使用MySQL(5.6)查询吗?

2 个答案:

答案 0 :(得分:0)

我并不认为它们是直接执行此操作的方法,例如在更高版本中,添加了许多const useNode = false; const request = useNode ? require('request-promise-native') : require('axios'); const postRequest = useNode ? postNode : postAxios; const MaxBatchSize = 100; const MaxRequests = 20000; const MaxIterations = MaxRequests / MaxBatchSize; (async () => { console.info('Going to send %i POST requests.', MaxRequests) console.info('Start time: %s', (new Date()).toTimeString()); const hrstart = process.hrtime(); for (var i = 0; i < MaxIterations; i++) { var promises = []; for (var j = 0; j < MaxBatchSize; j++) { promises[j] = postRequest(); } await Promise.all(promises); } var hrend = process.hrtime(hrstart); console.info('End time : %s', (new Date()).toTimeString()); console.info('Elapsed : %ds %ims', hrend[0], hrend[1] / 1000000); console.info('Rate : %i req/s', MaxRequests / (hrend[0] + hrend[1] / 1000000000)); })(); // Use with 'axios' function postAxios() { return request.post('http://192.168.1.106:9000/api/reports/new', { Hash: 'payload', Count: 22 }); } // Use with 'request-promise-native' function postNode() { var options = { method: 'POST', uri: 'http://192.168.1.106:9000/api/reports/new', body: { Hash: 'payload', Count: 22 }, json: true }; return request(options); } @Override public void onMessageReceived(RemoteMessage remoteMessage) { Log.e(TAG, "From: " + remoteMessage.getFrom()); Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString()); if (remoteMessage.getNotification() == null) return; // Check if message contains a notification payload. if(remoteMessage.getNotification() != null) { handleNotification(remoteMessage, remoteMessage.getNotification().getBody(), remoteMessage.getNotification().getTitle()); } 等json支持。您可能必须编写自己的自定义函数。 / p>

答案 1 :(得分:0)

对于MySQL 5.6,由于它不具有JSON数据类型或支持功能,因此,如果要更改字符串中JSON文档的任何部分,则必须通过UPDATE查询替换整个字符串。