Re: loadfile with quotation marks -> csv-file
Posted in 2005
try_and_err wrote:
> thanks for your interest, Jonathan.
> As i write before, sqlreload doesn't work. As i understand, i can only
> use sqlreload for an input file (-i) - right ?
> -> sqlcmd: invalid option i
> Or have i made a mistake ?
Well, 'sqlcmd -R' is equivalent to 'sqlreload'; you can only directly
specify '-i' on the command line with one of those two options.
However, there's nothing to stop you using a LOAD or RELOAD statement.
If you have v77.03 of SQLCMD, you can specify the format in the LOAD
statement (but not RELOAD - that's a simple oversight bug fixed in 77.05
which should be available on Monday):
LOAD FROM "input.file" FORMAT "csv" INSERT INTO TargetTable;
Or:
sqlcmd -R -d database -t targtetable -F csv -i input.file
> The Question is'nt how i would embed a double quote inside a field
> enclosed in double quotes, but how would do this excel:
> 1,"""ABC,D"""
> 2,"ABC,D"
> First line is with double quote as input ("ABC,D"), second line only
> letters (ABC,D).
OK - thanks for the help. I also perused Kernighan & Pike "The Practice
of Programming", which agrees with you. SQLCMD 77.05 (or any immediate
successor version that is actually released on the general public) will
have a fix to the code so that such CSV data is read correctly.
> DBD::CVS isn't a complete solution, but you can use this module to
> create your own solution. The perl script i found is a complete
> solution...
> It might be useful for others, when a tool for Informix exist, that
> can handle CSV files (don't forget the first line, that is the field
> names), because Informix can't handle that (but other databases can
> handle CSV files).
>
> Regards,
> try_and_err
>
>
>
>>Maybe, but probably not. I would have tried SQLCMD first (mainly
>>because I wrote it), and I'd worry about whether it handled the
>>"ABC,DEF" field correctly (and the other unquoted non-numeric
>
> strings).
>
>> I need to investigate, and fix if necessary. How would you embed a
>>double quote inside a field enclosed in double quotes?
>>
>>If that failed, I'd look at DBD::CSV and related Perl stuff.
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2005.01 -- http://dbi.perl.org/