试想一下,如果一个文件5G、10G甚至更大。如何将它迅速地加载到数据库指定的表呢?我们看看Sybase IQ是如何迅速地将表的数据加载到数据库的。
数据文件格式:
1440,2011-01-09 00:00:00,1,珠海,1,C网,8612345678222,221943,1,12175,1,12,14426467,1191632,9,
1440,2011-01-09 00:00:00,1,珠海,1,C网,8612345678222,968852,1,82077,1,7,2430696,134921,5,
1440,2011-01-09 00:00:00,1,珠海,1,C网,8612345678222,936862,3,10847,1,5,4585323,362630,5,
1440,2011-01-09 00:00:00,1,珠海,1,C网,8612345678222,308796,2,5614,2,12,14401931,1202200,11,
1440,2011-01-09 00:00:00,1,珠海,2,固网,861234567000,11058523,6,984391,3,19,12789576,1113565,19,
据以“,”分割。并以“,”结尾。
commit; lock table iqloadtest in write mode wait '00:05:00'; Set temporary option conversion_error='off'; Set temporary option escape_character='on'; Set temporary option load_memory_mb=256;
Set temporary option timestamp_format='YYYY-MM-DD HH:mm:ss';--解决时间格式问题 LOAD TABLE iqloadtest ( col1 ',', col2 ',', col3 ',', col4 ',', col5 ',', col6 ',', col7 ',', col8 ',', col9 ',', col10 ',', col11 ',', col12 ',', col13 ',', col14 ',', col15 ',\x0a',--最后一个字段顺便过滤掉换行符0a
filler(1)--在此例子中加了此条语句最后一行数据不被加载 ) FROM '/home/test/test.load' ESCAPES OFF QUOTES OFF IGNORE CONSTRAINT ALL 0 MESSAGE LOG '/home/test/iqMsg.log' ROW LOG '/home/test/iqRow.log' ONLY LOG ALL Notify 50000 WITH CHECKPOINT ON; commit;
结论:如果行结束符后面带了分隔符的话必须用此种方式。否则无法加载。
如果行结束符后面不带分隔符的话可以用filler(1)这种方式
IQLoad 会遇到的问题。
1、 ODBC 与 JDBC 的默认设置不一样。 JDBC 需要加上
Set temporary option escape_character='on';
2、当数据中存在null时的解决方法
commit; lock table iqloadtest in write mode wait '00:05:00'; Set temporary option conversion_error='off'; Set temporary option escape_character='on'; Set temporary option load_memory_mb=256; Set temporary option timestamp_format='YYYY-MM-DD HH:mm:ss'; LOAD TABLE iqloadtest ( 字段1 '分隔符' null('NULL'), 字段2 '分隔符' null('NULL'), col15 '分隔符\x0a' null('NULL'), filler(1)--在此例子中加了此条语句最后一行数据不被加载 ) FROM '/home/test/test.load' ESCAPES OFF QUOTES OFF IGNORE CONSTRAINT ALL 0 MESSAGE LOG '/home/test/iqMsg.log' ROW LOG '/home/test/iqRow.log' ONLY LOG ALL Notify 50000 WITH CHECKPOINT ON; commit;