How to UPDATE JSON column completely in MySql 5.7? - mysql-5.7

I am new to MySQL 5.7. I have a table with a JSON column.
data:{"Game": "Cricket","Player":"Dhoni"}
This is just a sample JSON object but I have plenty of key,value pairs in my column.
I want to replace my JSON completely with new JSON object that I am receiving as a response from some API
e.g.
{"Game": "Hockey","Player":"Kohli","":"",..........}
Please suggest a method for the same.Thanks

To update the JSON completely in MySQL version >= 5.7, simply use the UPDATE query and it will work.
For example:
UPDATE json_table SET json = '{"Game": "Hockey","Player":"Kohli"}' (WHERE CLAUSE)

Related

How do I write this query without using raw query in sequelize?

I would like to a bulk update in sequelize. Unfortunately it seems like sequelize does not support bulk updates I am using sequelize-typescript if that helps and using postgresql 14
My query in raw SQL looks like this
UPDATE feed_items SET tags = val.tags FROM
(
VALUES ('ddab8ce7-afa3-824f-7b65-edfb53a71764'::uuid,ARRAY[]::VARCHAR(255)[]),
('ece9f2fc-2a09-4a95-16ce-07293b0a14d2'::uuid,ARRAY[]::VARCHAR(255)[])
) AS val(id, tags) WHERE feed_items.id = val.id
I would like to generate this query from a given array of string and array values. The tags is implemented as a string array in my table.
Is there a way to generate the above query without using raw query?
Or an SQL injection safe way of generating the above query?

How to fetch raw sql insert/update from sqlalchemy ORM

I was trying to dump my PostgreSQL database created via SQLalchemy using python script. Though I have successfully created a database and all the data are getting inserted via web parsing in the ORM I have mapped with. But when I am trying to take a dump for all my insert queries using this
tab = Table(table.__tablename__, MetaData())
x = tab.insert().compile(
dialect=postgresql.dialect(),
compile_kwargs={"literal_binds": True},
)
logging.info(f"{x}")
I am adding values using ORM like this:
for value in vertex_type_values:
data = table(
Type=value["type"],
Name=value["name"],
SizeX=value["size_x"],
SizeY=value["size_y"],
SizeZ=value["size_z"],
)
session.add(data)
session.commit()
here table is the model which i have designed and imported from my local library and vertex_type_values which I have extracted and yield in my script
I am getting the output as
INSERT INTO <tablename> DEFAULT VALUES
So my question is how to get rid of Default Values and get actual values so that I can directly use insert command if my DB crash anytime? I need to know raw SQL for insert command

Logstash JDBC - how to process json field?

I have postgresql which stores some data as json fields, eg:
{"adults":2,"children":{"total":0,"ages":[]}}
I'm using logstash-input-jdbc plugin to process the data
How do i parse json from jdbc? From logs i see that the fields arrive as PGObject:
"travelers_json" => #<Java::OrgPostgresqlUtil::PGobject:0x278826b2>
which has a value and type properties.
I've tried using json filter, but i don't know how to access the value property to feed to json filter?
What i've tried:
source => "[travelers_json][value]"
source => "travelers_json.value"
source => "%{travelers_json.value}"
I must be missing something very obvious here?
Ok, so the simpliest way was to convert json to text in postgresql:
SELECT travelers_json::TEXT from xxx
but i still would like to know how to access that PGobject

Reading Cassandra Map in Node.js

I have table created using map in cassandra, Now i am trying to read the table from node.js and it returns object for the map, can i get the item count in a map and loop through it to get the items in the map?
table script
create table workingteam (teamid bigint primary key, status map)
You did not post a lot of details. First you will need to study the object Cassandra sends you. Good way to start would be to convert it to the JSON format and dump to the output through log.
console.log("Cassandra sent: %j", object);
I'm guessing in this object you will find attributes like connection parameters, host, client etc, but also something iterative that will contain keys and values.

how to refresh yui3 datatable with updated json data

I want to refresh datatable using new data in json format.
I tried using below method but it is giving error mentioned
var myData = table.get('data');
myData.add(json_data);
Error in console log:
invalid 'in' operand config
userTargets = (config && BUBBLETARGETS in config);
Please can someone shed some light if there's any other menthod to refresh yui3 datatable using new data
Thanks in advance.
It sounds like the json data you're passing it isn't an array of objects. Maybe it's an object with the array of objects nested inside somewhere?
At any rate, you can do
table.set('data', json_data.path.to.resultArray);
If you want to append more records to the table, try
table.addRows(json_data.path.to.resultArray);
HTH
It worked fine when I used eval to json_data (which was encoded in Perl from string into Json format)
table.set('data', eval(json_data));

Resources