Load Data Infile - edit a field
am 18.01.2006 03:35:26 von Michael BlairI would like to edit an incoming date field which is mm/dd/yyyy and
convert it to yyyy-mm-dd as required by mysql.
Any ideas?
I would like to edit an incoming date field which is mm/dd/yyyy and
convert it to yyyy-mm-dd as required by mysql.
Any ideas?
"Michael Blair"
news:OPhzf.920$NS6.612@newssvr30.news.prodigy.com...
>I would like to edit an incoming date field which is mm/dd/yyyy and convert
>it to yyyy-mm-dd as required by mysql.
There's no field-editing facility in LOAD DATA INFILE.
One solution would be:
1. Create your table with a CHAR field instead of a DATE field.
2. Load the data as is into the CHAR field.
3. Add a new DATE field.
4. Use UPDATE to set the DATE field based on the value in the CHAR field,
using an expression using the builtin STR_TO_DATE() function:
UPDATE myTable SET dateField = STR_TO_DATE(charField, '%m/%d/%Y');
5. Drop the old CHAR field.
Another option would be to use Perl or a text editor to reformat the dates
in the input file before you load it.
Regards,
Bill K.
Bill Karwin wrote:
> "Michael Blair"
> news:OPhzf.920$NS6.612@newssvr30.news.prodigy.com...
>
>>I would like to edit an incoming date field which is mm/dd/yyyy and convert
>>it to yyyy-mm-dd as required by mysql.
>
>
> There's no field-editing facility in LOAD DATA INFILE.
>
> One solution would be:
> 1. Create your table with a CHAR field instead of a DATE field.
> 2. Load the data as is into the CHAR field.
> 3. Add a new DATE field.
> 4. Use UPDATE to set the DATE field based on the value in the CHAR field,
> using an expression using the builtin STR_TO_DATE() function:
> UPDATE myTable SET dateField = STR_TO_DATE(charField, '%m/%d/%Y');
> 5. Drop the old CHAR field.
>
> Another option would be to use Perl or a text editor to reformat the dates
> in the input file before you load it.
>
> Regards,
> Bill K.
>
>
Sounds like a good solution, Thanks!