I am building a stats table that tracks user data points. The JSON is dynamic and can grow for multiple levels. I'm basically getting an error about invalid JSON using json_merge_patch, which I have used often before. I can not figure out why this is giving me the following error:
ERROR: Invalid JSON text in argument 1 to function json_merge_patch: "Invalid value." at position 0.
insert into
stats.daily_user_stats
VALUES
(null,'2022-02-02',1,18,3,'{"pageviews":{"user":1}}')
on duplicate key update
jdata =
if(
json_contains_path(jdata, 'one', '$.pageviews.user'),
json_set(jdata, '$.pageviews.user', cast(json_extract(jdata, '$.pageviews.user')+1 as UNSIGNED)),
json_merge_patch('jdata','{"pageviews":{"user":1}}')
)
Any help on identifying why the JSON I'm passing to the json_merge_function is not correct?
Solved. The json_merge_patch should look like this:
json_merge_patch(jdata,'{"pageviews":{"user":1}}')
Related
Trying to query az repos policy list with query of:
[?type.displayName=='Build' && contains(settings.displayName, 'Test')] returning message:
Invalid jmespath query supplied for `--query`: In function contains(), invalid type for value: None, expected one of: ['array', 'string'], received: "null"
Data is present while i query the fields, but when trying to query the value of them it is complaining.
tried with --query "[?contains(settings.displayName, 'Test')]" resulting in the same error.
I came across a link to bug query will traceback while attempting to filter a nullable field which contained instead a helpful explanation:
The reason for to_string() is that some service principals have their homepage set to null which is not an array or string. So the jmespath library fails.
This can be remedied by calling to_string on each object's homepage field so that homepage is always a string for the purposes of contains()
so i updated my query: az repos policy list --query "[?type.displayName=='Build' && contains(to_string(settings.displayName), 'Test') ]"
which returned my exspected output.
Thanks.
One of the workaround you can follow to resolve the above issue;
You can specify the space between )& ] in the last section as suggested in this SO THREAD by #rcarrington
For example:-
--query "[?contains(settings.displayName, 'Test') ]"
If the above does not work then please try to give a space between ? & contains .
For more information please refer this MICROSOFT DOCUMENTATION| How to query Azure CLI command output using a JMESPath query .
I'm trying to obtain information from a API's response in the DB. The column is a text type.
So I'm using the following code in the SELECT part:
SELECT KA.id,
KA.response::json -> 'SearchComplianceAlertsResponse' -> 'TransactionResult' ->> 'ResultText' AS result_text,
KA.response::json -> 'SearchComplianceAlertsResponse' -> 'TransactionResult' ->> 'ResultMessage' AS result_description
FROM KA
When I export that as a CSV I'm getting weird information at the end of the CSV:
Also, when I try to join the table with the code from above I'm getting the error mentioned in the title of the question. But When I run the query separately I don't have any issues running it.
I am using R2dbc jasync driver to generate and execute update query on my mysql db table containing a json column.
I am trying to do a JSON_SET operation on a column using R2dbcEntityTemplate and org.springframework.data.relational.core.query.Update.update and org.springframework.data.relational.core.query.Update.set methods. I am trying to generate a query equivalent to
UPDATE mytable SET json_col = JSON_SET(json_col, '$.path_to_update', CAST('{"a":"b"}' AS JSON)) WHERE id=:id
But I get the following error:
invalid json text: "the document is empty." at position 0 in value for column
From what I understand is the Update.set() operation is not delegating the JSON_SET operation to the DB but the DB is trying to interpret the generated string as json which is not valid json at position 0.
How can I achieve this using Update.set() function to delegate the MySQL function call to the DB before DB interprets the value as JSON ?
I tried using dbClient.sql().bind() and it worked but using dbTemplate.update() this is not working.
Good day,
Hope you are well.
I am trying to use the Vincere API, and trying to query the response to only return where private_job:0. I am using Postman to test the API.
When I use the below request, doing my best to follow the instructions on the Documentation:
https://domain.vincere.io/api/v2/job/search/fl=job_title,private_job;sort=published_date asc?q=private_job:0
I get the following response:
"Parse exception Unexpected end of input, expected term_char, ws0, term or term_end (line 1, pos 14):\nprivate_job:0\n ^\n"
If I remove ?q=private_job:0, I get a valid response.
I am clearly doing something wrong. Please assist.
in query parameter the key name is q ,
q=private_job:0
but in documentation it says instead of q it should be fq
https://domain.vincere.io/api/v2/job/search/fl=job_title,private_job;sort=published_date asc?fq=private_job:0
Also if you are using special character q=private_job:0 # , then give the value in the query parameter session of postman it will url encode it automatically for you
This stumped me as well, turns out my issue was twofold.
Firstly, this error refers to their URL parser expecting to see the end character %23, so your query string needs to end with that.
Secondly, I was attempting to query the job_type and using the actual string value ie. job_type:PERMANENT%23. This actually needs to be the enum value (1 in this case).
I am struggle with JSON and MySQL. I am trying to append to a JSON object.
Object has this form:
[{},{},...]
SELECT JSON_ARRAY_APPEND(my_meta, '$[0]', '{"private_key": "adfadf"}')
FROM my_object where user_id='11111'
I get the below error using 5.7.8-rc
Error Code: 1305. FUNCTION JSON_ARRAY_APPEND does not exist
So how do append then given I follow the docs?