Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert value for bit column of mysql

Tags:

mysql

I want to insert the value into a bit type column in MySQL. But I am getting a data truncation error.

CREATE TABLE `BITTESTTABLE` (
  `db_field` varchar(50) NOT NULL,
   `is_editable` bit(1) NOT NULL
  ) ENGINE=InnoDB DEFAULT CHARSET=latin1

If I am inserting a row with

INSERT INTO BITTESTTABLE values('XYZ','0')

I am getting

Data too long for column 'is_editable' at row 1

So how do I insert the data for bit type column?

like image 285
SrinivasDJ Avatar asked Jan 01 '16 10:01

SrinivasDJ


2 Answers

You should use:

INSERT INTO `BITTESTTABLE` VALUES('XYZ', b'0');
like image 75
Kevin Avatar answered Oct 17 '22 06:10

Kevin


Since bit is a number not a string you need enter it like

INSERT INTO BITTESTTABLE values('XYZ',0)
like image 8
Ahmed Khan Avatar answered Oct 17 '22 08:10

Ahmed Khan