Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从mysql中的位字段内的CSV加载数据_Mysql_Csv_Sql Insert - Fatal编程技术网

从mysql中的位字段内的CSV加载数据

从mysql中的位字段内的CSV加载数据,mysql,csv,sql-insert,Mysql,Csv,Sql Insert,在'MySQL'中的bit(1)类型的列中插入值的正确语法是什么 我的列定义是: payed bit(1) NOT NULL 我正在从一个csv加载数据,数据保存为0或1。 我已尝试使用以下方法进行插入: b'value' or 0bvalue (example b'1' or 0b1) 如图所示 但我一直在犯这样的错误: Warning | 1264 | Out of range value for column 'payed' at row 1 插入位的正确方法是什么 我不是手动插入

在'MySQL'中的
bit(1)
类型的列中插入值的正确语法是什么

我的列定义是:

payed bit(1) NOT NULL
我正在从一个
csv
加载数据,数据保存为
0
1
。 我已尝试使用以下方法进行插入:

b'value' or 0bvalue (example b'1' or 0b1)
如图所示

但我一直在犯这样的错误:

 Warning | 1264 | Out of range value for column 'payed' at row 1
插入
位的正确方法是什么

我不是手动插入,而是从
csv
(使用
load data infle
)加载数据,其中列的数据为
0
1

这是我的
load
查询,我已重命名隐私问题的字段,该定义中没有错误:

load data local infile 'input_data.csv' into table table
fields terminated by ',' lines terminated by '\n'
(id, year, field1, @date2, @date1, field2, field3, field4, field5, field6, payed, field8, field9,   field10, field11, project_id)
set
date1 = str_to_date(@date1, '%a %b %d %x:%x:%x UTC %Y'),
date2 = str_to_date(@date2, '%a %b %d %x:%x:%x UTC %Y');
show warnings;
这是我的CSV的一个示例行:

    200014,2013,0.0,Wed Feb 09 00:00:00 UTC 2014,Thu Feb 28 00:00:00 UTC 2013,2500.0,21,Business,0,,0,40.0,0,PROSPECT,1,200013
更新: 我没有找到使用
bit
的解决方案,因此我将列数据类型从
bit
更改为
tinyint
,以使其正常工作。

您可以使用如下函数:

INSERT INTO `table` VALUES (`column` = BIN(1)), (`column` = BIN(0));

让我猜猜,但我认为您应该忽略加载查询中CSV文件的第一行


请参阅“忽略数字行”

将csv中的“0”值完全替换为无值。这对我很有用。

我终于找到了解决方案,我把它贴在这里供将来参考。我已经在医院找到了帮助

因此,出于测试目的,我的表结构是:

+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id     | int(11)     | NO   | PRI | NULL    |       |
| nome   | varchar(45) | YES  |     | NULL    |       |
| valore | bit(1)      | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
我的
csv
测试文件是:

1,primo_valore,1
2,secondo_valore,0
3,terzo_valore,1
csv
加载到表中的查询是:

 load data infile 'test.csv' into table test
    fields terminated by ',' lines terminated by '\n'
    (id, nome, @valore) set
       valore=cast(@valore as signed);
    show warnings;

正如您所看到的那样,加载
csv
您需要执行强制转换
强制转换(@valore As signed)
,并且在
csv
中,您可以使用整数符号
1
0
来指示
位的值。这是因为无法使用二进制表示法加载位值(例如,
b'011010'
)。

是否尝试插入0或1?个人而言,我使用
smallint(1)unsigned
来存储布尔值。你能显示你的插入状态吗?@echo_me:我不是手动插入,我是从CSV加载数据,其中数据保存为0或1PL显示你的加载查询和CSV中的示例行。我添加了加载查询并从我的CSV中摘录。可读性不强,但问题是将csv中的0或1值插入位(1)列。谢谢,但我正在删除csv的第一行。在对相同的问题进行一些实验后,对于位字段,文本文件中的值被解释为“是否有值(1)或没有值(0)”。任何值,如0,12134、'True','foo','bla'都被解释为(1)