MySQL Forums
Forum List  »  Docs

manpage proposal: LOAD DATA INFILE -- writing NULLs
Posted by: Bert Cooper
Date: November 12, 2006 09:18AM

the question comes about on the complications of '' or ,, or otherwise "empty values" at column placeholders when writing to a database from a datafile.

Unlike a NULL value (which on an included column in a LOAD DATA TABLE operation can be only be written to a datatable by explicit declaration of NULL or \N in the datafile) an empty placeholder in a datafile will for an included string column write to the datatable an empty string (a NOT NULL value with length=0) and for a numeric column an explicit 0 (also a NOT NULL value).

This can have unseen repercussions, and IMHO the manpages might make mention of it just after the statement ... "An empty field value is interpreted differently than if the field value is missing: ..." toward the bottom of the LOAD DATA INFILE chapter.

When a datafile has a ,, or "" as empty place holder for a column which must be included (to write data for other rows for that column), declarations of NOT NULL DEFAULT=x in the column definition will be ignored on the empty placeholder, as it is interpreted as EMPTY but NOT NULL. NULL can be written to a database, and thereby invoke the DEFAULT=value in a column definition, only by exclusion of the entire column, or by explicit declaration of each NULL in that column. Where a column has many NULL values, and few explicit ones, it may be better to drop the column from the main LOAD DATA INFILE, and read it into a temp table with a text column even if it is numeric data (so that empty placeholder 0's are not commingled with datafile 0's). The main table can be updated using a WHERE expression from the temp table.

It would be nice to have an option to choose between [empty string,0,date | NULL] on empty placeholders. Maybe add a statement too the FIELDS clause,
[FIELDS
        [TERMINATED BY 'string']
        [[OPTIONALLY] ENCLOSED BY 'char']
        [ESCAPED BY 'char']
        [WRITE EMPTY PLACEHOLDERS AS [EMPTY | NULL] ]

Bert.



Edited 3 time(s). Last edit at 11/12/2006 04:59PM by Bert Cooper.

Options: Reply• Quote


Subject
Views
Written By
Posted
manpage proposal: LOAD DATA INFILE -- writing NULLs
11936
November 12, 2006 09:18AM
4833
January 05, 2007 11:24AM
11123
January 05, 2007 11:40AM
6249
December 02, 2007 07:00AM
5655
December 02, 2007 06:58AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.