i have to convert a bad code to a better solution for calculating counts from our site. i have a table that counts the number of times
the current table:
CREATE TABLE `hits_2011_12_5` (
`count` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
now i want to slowly migrate the new code to the old one but i have this error with the new code:
ana@localhost:test> insert into hits_2011_12_5 values (1,2,3,4,5);
ERROR 1136 (21S01): Column count doesn't match value count at row 1
what can be the issue?
The INSERT IGNORE command keeps the first set of the duplicated records and discards the remaining. The REPLACE command keeps the last set of duplicates and erases out any earlier ones. Another way to enforce uniqueness is to add a UNIQUE index rather than a PRIMARY KEY to a table.
The INSERT OVERWRITE INTO SELECT statement writes data to AnalyticDB MySQL by using external tables. To write data to AnalyticDB MySQL, you must define an external table of a specific data source in AnalyticDB MySQL and execute the INSERT OVERWRITE INTO SELECT statement.
There are three ways you can perform an “insert if not exists” query in MySQL: Using the INSERT IGNORE statement. Using the ON DUPLICATE KEY UPDATE clause. Or using the REPLACE statement.
You can also use INSERT ... TABLE in MySQL 8.0. 19 and later to insert rows from a single table. INSERT with an ON DUPLICATE KEY UPDATE clause enables existing rows to be updated if a row to be inserted would cause a duplicate value in a UNIQUE index or PRIMARY KEY .
use this:
ana@localhost:test> insert into hits_2011_12_5 values (1),(2),(3),(4),(5);
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0
The query you tried requires 5 columns, not inserting 5 lines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With