0

Why does INSERT '0' in bit(1), produce an error:

#1406 - Data too long for column [del] at row [del].

If I INSERT 0 (like int) everything is fine. Why doesn't the field want to automatically convert the string to an integer?

Igor F.
  • 2,649
  • 2
  • 31
  • 39
Student
  • 31
  • 4
  • it's the same reason why a string cannot be casted to a bit https://stackoverflow.com/questions/6918897/how-can-i-cast-an-int-to-a-bit-in-mysql-5-1 – Luuk Feb 12 '20 at 13:28
  • 1
    @Luuk Strange logic. This is sad. – Student Feb 12 '20 at 13:56

2 Answers2

0

Try:

INSERT '0'='0';
INSERT '0'='1';

to insert resp. true and false.

Luuk
  • 12,245
  • 5
  • 22
  • 33
  • I use SQL in php, and 0 for bit, this is an array element: $bar['foo'] = "0"; $stmt->bindParam(':foo', $bar['foo']); – Student Feb 12 '20 at 13:57
0

Single quotes are for literals, here is a great explanation

https://stackoverflow.com/a/14123649/5754159

Roberto Clavijo
  • 149
  • 1
  • 6