insert-on-duplicate-key icon indicating copy to clipboard operation
insert-on-duplicate-key copied to clipboard

Creating wrong record

Open stebogit opened this issue 7 years ago • 3 comments

Hi, I noticed that in some particular cases the insertOnDuplicateKey method creates a wrong record in the table. This is an example of input with the table schema, at the very bottom. Simply inserting the data, starting from an empty table,

AwnRecord::insertOnDuplicateKey($records);

results in the insertion of only 50 records (out of 92 as input) one of which is totally wrong and even invalid, i.e. the is_valid_solarRad field, defined as boolean, is equal to 127 and tstamp, a datetime field, equals 0000-00-00 00:00:00 (which I believe it's not a valid datetime value)

screen shot 2017-11-25 at 1 17 06 am

What's wrong with the code/data? How can the database even allow for creating an invalid type field? If of any relevance, I noticed the not inserted records are mostly empty, although null is a valid value for those columns (and relevant data in my case).

stebogit avatar Nov 25 '17 09:11 stebogit

How many unique index is on the table?

The only way I think I can fix the issue if I can replicate it.

Do you have a simple example of a table schema and data to insert.

yadakhov avatar Nov 26 '17 21:11 yadakhov

Sorry @yadakhov I linked the gist but it was probably not really visible. Here you can fine both data and the table schema that in my case generates the issue: https://gist.github.com/stebogit/5b9f2a7cf31ad468ece4bada2c85f91a

The PK is the combination of station_id and tstamp: PRIMARY KEY (station_id, tstamp)

stebogit avatar Nov 27 '17 00:11 stebogit

I'll take a look when I got some free time.

I'm suspecting it's the composite primary key. PRIMARY KEY (station_id, tstamp)

yadakhov avatar Nov 27 '17 22:11 yadakhov