9
9
create table t1 (a date, b date, c date not null, d date);
10
load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',';
11
load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES;
10
load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',';
11
load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' IGNORE 2 LINES;
15
load data infile '../std_data_ln/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d);
15
load data infile '../../std_data/loaddata1.dat' into table t1 fields terminated by ',' LINES STARTING BY ',' (b,c,d);
19
19
create table t1 (a text, b text);
20
load data infile '../std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by '''';
20
load data infile '../../std_data/loaddata2.dat' into table t1 fields terminated by ',' enclosed by '''';
21
21
select concat('|',a,'|'), concat('|',b,'|') from t1;
24
24
create table t1 (a int, b char(10));
25
load data infile '../std_data_ln/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines;
25
load data infile '../../std_data/loaddata3.dat' into table t1 fields terminated by '' enclosed by '' ignore 1 lines;
28
load data infile '../std_data_ln/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines;
28
load data infile '../../std_data/loaddata4.dat' into table t1 fields terminated by '' enclosed by '' lines terminated by '' ignore 1 lines;
30
30
# The empty line last comes from the end line field in the file
109
109
create table t1 (a int default 100, b int, c varchar(60));
110
110
# we can do something like this
111
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set b=@b+10, c=concat("b=",@b);
111
load data infile '../../std_data/rpl_loaddata.dat' into table t1 (a, @b) set b=@b+10, c=concat("b=",@b);
112
112
select * from t1;
113
113
truncate table t1;
114
114
# we can use filled fields in expressions
115
115
# we also assigning NULL value to field with non-NULL default here
116
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (a, @b) set c= if(a is null,"oops",a);
116
load data infile '../../std_data/rpl_loaddata.dat' into table t1 (a, @b) set c= if(a is null,"oops",a);
117
117
select * from t1;
118
118
truncate table t1;
119
119
# we even can use variables in set clause, and missed columns will be set
120
120
# with default values
122
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, b) set c= if(@a is null,@c,b);
122
load data infile '../../std_data/rpl_loaddata.dat' into table t1 (@a, b) set c= if(@a is null,@c,b);
123
123
select * from t1;
124
124
# let us test side-effect of such load
125
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@a, @b);
125
load data infile '../../std_data/rpl_loaddata.dat' into table t1 (@a, @b);
126
126
select * from t1;
128
128
truncate table t1;
129
129
# Reading of all columns with set
130
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 set c=b;
130
load data infile '../../std_data/rpl_loaddata.dat' into table t1 set c=b;
131
131
select * from t1;
132
132
truncate table t1;
133
133
# now going to test fixed field-row file format
134
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c="Wow";
134
load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c="Wow";
135
135
select * from t1;
136
136
truncate table t1;
137
137
# this also should work
138
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c=concat(a,"+",b,"+",@c,"+",b,"+",if(c is null,"NIL",c));
138
load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, b) set c=concat(a,"+",b,"+",@c,"+",b,"+",if(c is null,"NIL",c));
139
139
select * from t1;
140
140
# and this should bark
142
load data infile '../std_data_ln/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, @b);
142
load data infile '../../std_data/loaddata5.dat' into table t1 fields terminated by '' enclosed by '' (a, @b);
144
144
# Now let us test LOAD DATA with subselect
145
145
create table t2 (num int primary key, str varchar(10));
146
146
insert into t2 values (10,'Ten'), (15,'Fifteen');
147
147
truncate table t1;
148
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1 (@dummy,@n) set a= @n, c= (select str from t2 where num=@n);
148
load data infile '../../std_data/rpl_loaddata.dat' into table t1 (@dummy,@n) set a= @n, c= (select str from t2 where num=@n);
149
149
select * from t1;