MySql / MariaDb - syntax problem adding a row - mariadb
I have a mysql (MariaDB) table with a plenty of lines. I deleted by mistate a row.
And I would like to recover it from a backup.
This is the row I found in the sql backup file:
| 186 | {"price":8990,"quantity":1,"shipping":0,"electronicShipping":false,"description":"xxxx \"yyy uuu iii\" + xyz xyz","cname":"Name LastName","fname":"Name","email":"asdfdsa#afsfa.com","phone":"76543765","address":"sadfas123/avc","city":"XXX","state":"vvvv","zip":"654326","newsletter":true,"product":{"sku":"pakiet","name":"YUIa \"sdfghjk\" + xyz sfas","description":"YYYY \"xxxx yyyy zzzz\" + xyz xyz xyz + 3 xyz yyyy xxxx","originalPrice":149.6,"price":89.9,"vat":5,"shipping":0,"electronicShipping":false,"discount":59.7,"category":["drukowane","ebooki"],"image":"/images/xxx.jpg","shopImage":"/images/tyyyy.jpg","template":"d-idsgiosdjgiodjsgs","links":[{"file":"xyz.mobi","name":"File Name"},{"file":"zxvfsdfs.epub","name":"File name"},{"file":"sdfasfdw.pdf","name":"File name"},{"file":"asdgdsagds.pdf","name":"File name"}],"mailerLiteGroupID":[11111,22222],"sendgridListIds":["456789-54321-6543-654","76543-654327-6543"],"mailerLiteBuyersGroupID":[1234,12345]},"privacy":true,"terms":true,"comment":"","template":"d-234567890","vat":false,"vatCompany":"","vatNip":"","vatAddress":"","vatCity":"","vatState":"","vatZip":"","status":1,"extra":null,"selectAll":true,"statement":"34-3242-2345"} | 1 | 2021-12-24 15:21:52 | 2021-12-24 15:22:12 | 1560281088 | NULL | NULL |
I am trying to add it this way:
INSERT INTO Orders (id, body, state, createdAt, updatedAt, orderNumber, send, invoice)
-> VALUES (186, {"price":8990,"quantity":1,"shipping":0,"electronicShipping":false,"description":"xxxx \"yyy uuu iii\" + xyz xyz","cname":"Name LastName","fname":"Name","email":"asdfdsa#afsfa.com","phone":"76543765","address":"sadfas123/avc","city":"XXX","state":"vvvv","zip":"654326","newsletter":true,"product":{"sku":"pakiet","name":"YUIa \"sdfghjk\" + xyz sfas","description":"YYYY \"xxxx yyyy zzzz\" + xyz xyz xyz + 3 xyz yyyy xxxx","originalPrice":149.6,"price":89.9,"vat":5,"shipping":0,"electronicShipping":false,"discount":59.7,"category":["drukowane","ebooki"],"image":"/images/xxx.jpg","shopImage":"/images/tyyyy.jpg","template":"d-idsgiosdjgiodjsgs","links":[{"file":"xyz.mobi","name":"File Name"},{"file":"zxvfsdfs.epub","name":"File name"},{"file":"sdfasfdw.pdf","name":"File name"},{"file":"asdgdsagds.pdf","name":"File name"}],"mailerLiteGroupID":[11111,22222],"sendgridListIds":["456789-54321-6543-654","76543-654327-6543"],"mailerLiteBuyersGroupID":[1234,12345]},"privacy":true,"terms":true,"comment":"","template":"d-234567890","vat":false,"vatCompany":"","vatNip":"","vatAddress":"","vatCity":"","vatState":"","vatZip":"","status":1,"extra":null,"selectAll":true,"statement":"34-3242-2345"}, 1, 2021-12-24 15:21:52, 2021-12-24 15:22:12, 2634022912, NULL, NULL);
But it's giving me:
ERROR 1064 (42000): 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 '"price":8990,"quantity":1,"shipping":0,"electronicShipping":false,"description":' at line 2
Can anybody help me to add this line to the Orders table?
Related
SQLite, how can I find a value that in my sentence?
For example, a table like this: name | age | gender alice | 23 | female bob | 21 | male irfan | 24 | male ...... I get a sentence like "Hi, bob and alice!", I want to know the sentence if include the name in the table and return them. What should I do? Like: "Hi, bob and alice!" -> return the bob's value and alice value in the table How to write SQL statements?
Something like SELECT * FROM yourtable WHERE 'Hi, bob and alice!' LIKE '%' || name || '%'; is a start.
SQLite find table row where a subset of columns satisfies a specified constraint
I have the following SQLite table CREATE TABLE visits(urid INTEGER PRIMARY KEY AUTOINCREMENT, hash TEXT,dX INTEGER,dY INTEGER,dZ INTEGER); Typical content would be # select * from visits; urid | hash | dx | dY | dZ ------+-----------+-------+--------+------ 1 | 'abcd' | 10 | 10 | 10 2 | 'abcd' | 11 | 11 | 11 3 | 'bcde' | 7 | 7 | 7 4 | 'abcd' | 13 | 13 | 13 5 | 'defg' | 20 | 21 | 17 What I need to do here is identify the urid for the table row which satisfies the constraint hash = 'abcd' AND (nearby >= (abs(dX - tX) + abs(dY - tY) + abs(dZ - tZ)) with the smallest deviation - in the sense of smallest sum of absolute distances In the present instance with nearby = 7 tX = tY = tZ = 12 there are three rows that meet the above constraint but with different deviations urid | hash | dx | dY | dZ | deviation ------+-----------+-------+--------+--------+--------------- 1 | 'abcd' | 10 | 10 | 10 | 6 2 | 'abcd' | 11 | 11 | 11 | 3 4 | 'abcd' | 12 | 12 | 12 | 3 in which case I would like to have reported urid = 2 or urid = 3 - I don't actually care which one gets reported. Left to my own devices I would fetch the full set of matching rows and then dril down to the one that matches my secondary constraint - smallest deviation - in my own Java code. However, I suspect that is not necessary and it can be done in SQL alone. My knowledge of SQL is sadly too limited here. I hope that someone here can put me on the right path. I now have managed to do the following CREATE TEMP TABLE h1(v1 INTEGER,v2 INTEGER); SELECT urid,(SELECT (abs(dX - 12) + abs(dY - 12) + abs(dZ - 12))) devi FROM visits WHERE hash = 'abcd'; which gives --SELECT * FROM h1 urid | devi | -------+-----------+ 1 | 6 | 2 | 3 | 4 | 3 | following which I issue select urid from h1 order by v2 asc limit 1; which yields urid = 2, the result I am after. Whilst this works, I would like to know if there is a better/simpler way of doing this.
You're so close! You have all of the components you need, you just have to put them together into a single query. Consider: SELECT urid , (abs(dx - :tx) + abs(dy - :tx) + abs(dz - :tx)) AS devi FROM visits WHERE hash=:hashval AND devi < :nearby ORDER BY devi LIMIT 1 Line by line, first you list the rows and computed values you want (:tx is a placeholder; in your code you want to prepare a statement and then bind values to the placeholders before executing the statement) from the visit table. Then in the WHERE clause you restrict what rows get returned to those matching the particular hash (That column should have an index for best results... CREATE INDEX visits_idx_hash ON visits(hash) for example), and that have a devi that is less than the value of the :nearby placeholder. (I think devi < :nearby is clearer than :nearby >= devi). Then you say that you want those results sorted in increasing order according to devi, and LIMIT the returned results to a single row because you don't care about any others (If there are no rows that meet the WHERE constraints, nothing is returned).
SQLite UPDATE returns empty
I'm trying to update a table column from another table with the code below. Now the editor says '39 rows affected' and I can see something happened because some cells changed from null to empty (nothing shows). While orhers are still null What could be wrong here? Why does it not update properly.... PS: I checked manually that the values are not empty in the column to check for. UPDATE CANZ_CONC SET EAN = (SELECT t1.EAN_nummer FROM ArtLev_CONC t1 WHERE t1.Artikelcode_leverancier = Artikelcode_leverancier) WHERE ARTNMR IN (SELECT t1.Artikelcode_leverancier FROM Artlev_CONC t1 WHERE t1.Artikelcode_leverancier = ARTNMR); Edit: The tabel2 is like: NMR | EAN | CUSTOM ------------------------------- 1 | 987 | A 2 | 654 | B 3 | 321 | C Tabel 1 is like NMR | EAN | CUSTOM ------------------------------- 1 | null | null 2 | null | null 5 | null | null After the UPDATE table1 is like NMR | EAN | CUSTOM ------------------------------- 1 | | null 2 | | null 5 | null | null
I've got this working. I guess my data was corrupted after all. Since it is about 330.000 rows it was not very easy to spot. But it came to me when the loading of the data took about 10 minutes! It used to be about 40 - 60 seconds. So I ended up back at the drawing board for the initial csv file. I also saw the columns had not been given a DATA type, so I altered that as well. Thanx for the help!
How can I access the data in a Cassandra Table using RCassandra
I need to get the data in a column of a table Cassandra Database. I am using RCassandra for this. After getting the data I need to do some text mining on it. Please suggest me how do connect to cassandra, and get the data into my R Script using RCassandra My RScript : library(RCassandra) connect.handle <- RC.connect(host="127.0.0.1", port=9160) RC.cluster.name(connect.handle) RC.use(connect.handle, 'mykeyspace') sourcetable <- RC.read.table(connect.handle, "sourcetable") print(ncol(sourcetable)) print(nrow(sourcetable)) print(sourcetable) This will print the output as: > print(ncol(sourcetable)) [1] 1 > print(nrow(sourcetable)) [1] 18 > print(sourcetable) 144 BBC News 158 IBN Live 123 Reuters 131 IBN Live But my cassandra table contains four columns, but here its showing only 1 column. I need to get each column values separated. So how do I get the individual column values(Eg.each feedurl) What changes should I make in my R script? My cassandra table, named sourcetable
I have used Cassandra and R with the correct Cran Jar files, but RCassandra is easier. RCassandra is a direct interface to Cassandra without the use of Java. To connect to Cassandra you will use RC.connect to return a connection handle like this. RC.connect(host = <xxx>, port = <xxx>) RC.login(conn, username = "bar", password = "foo") You can then use a RC.get command to retrieve data or RC.ReadTable command to read table data. BUT, First you should read THIS
I am confused as well. Table demo.emp has 4 row and 4 columns ( empid, deptid, first_name and last_name). Neither RC.get nor RC.read.table gets the all the data. cqlsh:demo> select * from emp; empid | deptid | first_name | last_name -------+--------+------------+----------- 1 | 1 | John | Doe 1 | 2 | Mia | Lewis 2 | 1 | Jean | Doe 2 | 2 | Manny | Lewis > RC.get.range.slices(c, "emp", limit=10) [[1]] key value ts 1 1.474796e+15 2 John 1.474796e+15 3 Doe 1.474796e+15 4 1.474796e+15 5 Mia 1.474796e+15 [[2]] key value ts 1 1.474796e+15 2 Jean 1.474796e+15 3 Doe 1.474796e+15 4 1.474796e+15 5 Manny 1.474796e+15
Nicer visual formatting for sqlite3 tables?
How do I format table output in sqlite? For example, if the default behavior for showing entries is hard to read when one of the columns has variable length text. If I do select a,b,c from table I get a1|b1|c1 a2|b2|c2 while I want some nicer and easily readible formatting like.. ++++++++++++++++ | a1 | b1 | c1 | | a2 | b2 | c2 | ++++++++++++++++
you can use the dot.commands ".mode columns / .width" sqlite3 test.db <<SQL .mode columns .width 3 10 10 4 select 'ABCDEFGHIJKLM','ABCDEFGHIJKLM','ABC','ABCDEFGHIJKLM'; SQL will receive ABC ABCDEFGHIJ ABC ABCD but with no other formatings like borders etc, so very rudimentary ant
For sqlite3 you just need a command .mode table and your tables should look like this: +----------+-----------+ | per_id | per2_id | +----------+-----------+ | 13449958 | 5135490 | | 21085892 | 5135490 | | 3291872 | 5135490 | +----------+-----------+ In the case you want this to be permanent change, you need to write the same command .mode table in the file called .sqliterc (if it doesn't exist just make one) in your home directory. And that should do it.