MySQL how to specify string position with LOAD DATA INFILE -


i have ascii files static number of characters each line no delimiters. i'd use load data infile import table.

example of file:

usalalabama                                                                usararkansas                                                               usflflorida                                                                

the structure table:

country char(2) state char(2) name varchar(70)  create table `states` (   `country` char(2) collate latin1_general_ci not null,   `state` char(2) collate latin1_general_ci not null,   `name` varchar(70) collate latin1_general_ci not null ) engine=myisam default charset=latin1_general_ci collate=latin1_general_ci; 

is possible specify start , end position each column?

according the documentation, can load fixed format file without using temporary table.

if fields terminated , fields enclosed values both empty (''), fixed-row (nondelimited) format used. fixed-row format, no delimiters used between fields (but can still have line terminator). instead, column values read , written using field width wide enough hold values in field. tinyint, smallint, mediumint, int, , bigint, field widths 4, 6, 8, 11, , 20, respectively, no matter declared display width is.

the positions derived columns definitions, in case match structure of file. need do:

load data infile 'your_file' table your_table   fields terminated ''   lines terminated '\r\n'   set name = trim(name); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -