MySQL fields completed by tab

I am trying to download a tab delimited file from MySQL. I need a query that likes this: LOAD DATA LOCAL INFILE 'file' INTO TABLE tbl FIELDS TERMINATED BY 'TAB' Is there something I can do for TAB to make this work?

+5
source share
3 answers

You tried the '\ t' escape sequence + "T" counts as a tab ... did not try, but maybe what you need

+10
source

I just tried to find the answer to this question myself in order to save the repeated saving of my file with comma separation instead of tabs ...

From the old MySQL reference manual, a long way down the page, you may find that TAB is the default delimiter for files loaded using LOAD DATA in MySQL .

See: http://dev.mysql.com/doc/refman/4.1/en/load-data.html

I just uploaded the CSV file this way in MySQL5.1.

Bw

+1
source

fields end with '\ t'

Try this

Remarks:

Field and line processing

For the LOAD DATA and SELECT ... INTO OUTFILE statements, the syntax of the FIELDS and LINES clauses is the same. Both sentences are optional, but FIELDS must precede LINES if both are specified.

If you specify a FIELDS clause, each of its subitems (TERMINATED BY, [OPTIONALLY] ENCLOSED BY and ESCAPED BY) is also optional, except that you must specify at least one of them. The arguments to these items can only contain ASCII characters.

If you do not specify a FIELDS or LINES clause, the default values ​​will be the same as if you wrote this:

FIELDS STOPPED by '\ t', CLOSED '', CLOSED by '\\'

LINES TERMINATED '\ n' BEGIN ''

The backslash is the MySQL escape character in strings in SQL statements. Thus, to specify a literal backslash, you must specify two backslashes so that the value is interpreted as one backslash. The escape sequences '\ t' and '\ n' define tabs and newlines, respectively.

In other words, the default values ​​force LOAD DATA to act as follows when reading input:

Look for line boundaries on new lines.

Do not skip a single line prefix.

Break lines into fields on tabs.

Do not expect fields to be enclosed in quotation marks.

Interpret characters preceded by the escape character \ as escape sequences. For example, \ t, \ n, and \ mean tabs, newlines, and backslashes, respectively. See the FIELDS ESCAPED BY discussion later for a complete list of escape sequences.

Conversely, the default values ​​force SELECT ... INTO OUTFILE to act when writing output as follows:

Write tabs between fields.

Do not enclose fields in citation characters.

Use \ to avoid tab, newline, or \ instances that occur in field values.

Write new lines at the end of lines.

see: https://dev.mysql.com/doc/refman/8.0/en/load-data.html.

More details.

-2
source

Source: https://habr.com/ru/post/1306072/


All Articles