Вы находитесь на странице: 1из 1

62 Chapter 2: Inserting

QUOTES OFF
STRIP OFF;
The LOAD TABLE statement above uses the input value list ( line_text ) to
specify that the input file only contains data for the line_text column, not the
line_number column. The DEFAULTS ON option is used so the DEFAULT
AUTOINCREMENT feature will work to generate line_number values; by
default, the LOAD TABLE command does not fill in DEFAULT values. The
DELIMITED BY '' option specifies nothing should be treated as a field delim-
iter, and ESCAPES OFF says theres no need to look for escape characters
either. QUOTES OFF tells LOAD TABLE to treat leading quotes as part of the
data and to preserve leading spaces. STRIP OFF tells LOAD TABLE to pre-
serve trailing spaces.
Here is a sample input file designed to demonstrate some of the challenges
involved in getting LOAD TABLE to store the text without reformatting it:
This is a flat text file, containing free-form text with embedded
commas, 'single quotes', and "double quotes". Even lines with
'leading and trailing quotes will be stored as is.'
It will be stored in the line_text column as is, line-by-line, with
one line per row. Empty lines

will be ignored, but blank lines consisting of at least one space

will be stored. Trailing blanks will be stored,


and so will leading blanks.
Backslash characters \, \\, \\\, \\\\, etc., will be stored as is.
Here is what the raw_text table looks like when you run SELECT * FROM
raw_text ORDER BY line_number in ISQL. It shows that the empty line after
line 5 was ignored, but the line consisting of one space was stored as row 7.
Also, it shows that the trailing spaces were stored in row 8 as well as the leading
spaces in row 9.
# line_text
= =========
1 'This is a flat text file, containing free-form text with embedded'
2 'commas, ''single quotes'', and "double quotes". Even lines with'
3 '''leading and trailing quotes will be stored as is.'''
4 'It will be stored in the line_text column as is, line-by-line, with '
5 'one line per row. Empty lines'
6 'will be ignored, but blank lines consisting of at least one space '
7 ' '
8 'will be stored. Trailing blanks will be stored, '
9 ' and so will leading blanks.'
10 'Backslash characters \\, \\\\, \\\\\\, \\\\\\\\, etc., will be stored as is.'
LOAD TABLE is fast because it takes three shortcuts. First of all, it does not
fire any insert triggers. This doesnt mean that LOAD TABLE bypasses foreign
key checking; on the contrary, if you attempt to load a row that violates a refer-
ential integrity constraint, the LOAD TABLE statement will fail. But if you
have critical application logic in an insert trigger, it wont get executed, and you
may want to use another method to load data.
The second shortcut is that LOAD TABLE does not acquire locks on the
individual inserted rows but instead places an exclusive lock on the entire table.
This has implications for concurrency; if you run LOAD TABLE on a table
thats frequently updated by other users, two bad things might happen: The

Вам также может понравиться