Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalid mysql query on insert

Tags:

php

mysql

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?

like image 854
ana Avatar asked Dec 05 '11 12:12

ana


People also ask

What is insert ignore in MySQL?

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.

Does insert overwrite MySQL?

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.

Do not insert if exists MySQL?

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.

How does insert work in MySQL?

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 .


1 Answers

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.

like image 143
Book Of Zeus Avatar answered Nov 14 '22 02:11

Book Of Zeus