Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Fw: loadfile with quotation marks -> csv-file (SQLCMD and DB-Access and

113 views
Skip to first unread message

Jonathan Leffler

unread,
Mar 22, 2005, 7:36:13 PM3/22/05
to

This is a multipart message in MIME format.
--=_alternative 0003511C88256FCD_=
Content-Type: text/plain; charset="US-ASCII"

Jonathan Leffler <jlef...@earthlink.net> wrote on 03/21/2005 09:38:43 PM:
> try_and_err wrote:
> > Hmm, i'am really the first one with this problem ?
>
> 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?

It failed - the comma inside the quote is mishandled. I'll meditate on
whether it is worth fixin

> If that failed, I'd look at DBD::CSV and related Perl stuff.

Also look (in Google, IIUG) for csv2unl - a Perl script that Andrew Hamm
and I assembled around October 2002. If that is not readily discoverable,
I'll submit it to the IIUG. It converts CSV data to Informix UNLOAD
format, ready for use by - well, DB-Access, SQLCMD, DBLOAD, ... It uses
the Text::CSV module for Perl - you'd need to obtain that (and any of its
dependencies - I didn't notice any, but I have so many modules installed
it could be that I wouldn't notice).

> > ok, maybe this is useful for others:
> > When Informix has not a solution have a look on the competition:
> > I found a nice website with a solution for postgresql:
> > http://www.onlamp.com/onlamp/2004/12/09/examples/create_input_sql.pl
> > You have only to adapt your table schema, works also perfectly
forInformix.
>
> Looks as though it might be useful.
>
> > Regards,
> > try_and_err
> >
> > try_a...@web.de (try_and_err) wrote in message news:<fbcbd702.
> 050318121...@posting.google.com>...
> >
> >>ok, maybe my first explanation was to simple (or false):
> >>We have a standard CSV file (comma separated) from an extern firma to
> >>insert in an Informix table, like this:
> >>1,ABC,"ABC,DEF",DEF,2,,,
> >>2,BCD,EFG,"BCD,EFG",2,,,
> >>
> >>There were three problems (for Informix/dbaccess):
> >>- double quotes
> >>- comma in double quotes identified as delimiter
> >>- last column without finally delimiter (table has 8 columns)
> >>
> >>ok, i can write an (awk) script to fix these problems, but i am
> >>surprised that is it really not possible to load an normal and
> >>standard CSV file in Informix ?
> >>sqlreload doesn't work:
> >>env | grep DB
> >>DBQUOTE="
> >>DBDELIMITER=,
> >>sqlreload -d db1 -i test1.csv -t test1 -v -x
> >>SQL -846: Number of values in load file is not equal to number of
> >>columns.
> >>ISAM -746: Too many values in record
> >>It seems, that the comma in double quotes is already identified as
> >>delimiter...
> >>I have tried with and without an additionally delimiter (comma).
> >>Further suggestions ?


--
Jonathan Leffler (jlef...@us.ibm.com)
STSM, Informix Database Engineering, IBM Information Management Division
4100 Bohannon Drive, Menlo Park, CA 94025
Tel: +1 650-926-6921 Tie-Line: 630-6921
"I don't suffer from insanity; I enjoy every minute of it!"


--=_alternative 0003511C88256FCD_=
Content-Type: text/html; charset="US-ASCII"


<br><font size=2><tt>Jonathan Leffler &lt;jlef...@earthlink.net&gt; wrote
on 03/21/2005 09:38:43 PM:<br>
&gt; try_and_err wrote:<br>
&gt; &gt; Hmm, i'am really the first one with this problem ?<br>
&gt; <br>
&gt; Maybe, but probably not. &nbsp;I would have tried SQLCMD first (mainly
<br>
&gt; because I wrote it), and I'd worry about whether it handled the <br>
&gt; &quot;ABC,DEF&quot; field correctly (and the other unquoted non-numeric
strings). <br>
&gt; &nbsp; I need to investigate, and fix if necessary. &nbsp;How would
you embed a <br>
&gt; double quote inside a field enclosed in double quotes?<br>
</tt></font>
<br><font size=2><tt>It failed - the comma inside the quote is mishandled.
&nbsp;I'll meditate on whether it is worth fixin</tt></font>
<br><font size=2><tt><br>
&gt; If that failed, I'd look at DBD::CSV and related Perl stuff.<br>
</tt></font>
<br><font size=2><tt>Also look (in Google, IIUG) for csv2unl - a Perl script
that Andrew Hamm and I assembled around October 2002. &nbsp;If that is
not readily discoverable, I'll submit it to the IIUG. &nbsp;It converts
CSV data to Informix UNLOAD format, ready for use by - well, DB-Access,
SQLCMD, DBLOAD, ... &nbsp;It uses the Text::CSV module for Perl - you'd
need to obtain that (and any of its dependencies - I didn't notice any,
but I have so many modules installed it could be that I wouldn't notice).</tt></font>
<br><font size=2><tt><br>
&gt; &gt; ok, maybe this is useful for others:<br>
&gt; &gt; When Informix has not a solution have a look on the competition:<br>
&gt; &gt; I found a nice website with a solution for postgresql:<br>
&gt; &gt; http://www.onlamp.com/onlamp/2004/12/09/examples/create_input_sql.pl<br>
&gt; &gt; You have only to adapt your table schema, works also perfectly
forInformix.<br>
&gt; <br>
&gt; Looks as though it might be useful.<br>
&gt; <br>
&gt; &gt; Regards,<br>
&gt; &gt; try_and_err<br>
&gt; &gt; <br>
&gt; &gt; try_a...@web.de (try_and_err) wrote in message news:&lt;fbcbd702.<br>
&gt; 050318121...@posting.google.com&gt;...<br>
&gt; &gt; <br>
&gt; &gt;&gt;ok, maybe my first explanation was to simple (or false):<br>
&gt; &gt;&gt;We have a standard CSV file (comma separated) from an extern
firma to<br>
&gt; &gt;&gt;insert in an Informix table, like this:<br>
&gt; &gt;&gt;1,ABC,&quot;ABC,DEF&quot;,DEF,2,,,<br>
&gt; &gt;&gt;2,BCD,EFG,&quot;BCD,EFG&quot;,2,,,<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;There were three problems (for Informix/dbaccess):<br>
&gt; &gt;&gt;- double quotes<br>
&gt; &gt;&gt;- comma in double quotes identified as delimiter<br>
&gt; &gt;&gt;- last column without finally delimiter (table has 8 columns)<br>
&gt; &gt;&gt;<br>
&gt; &gt;&gt;ok, i can write an (awk) script to fix these problems, but
i am<br>
&gt; &gt;&gt;surprised that is it really not possible to load an normal
and<br>
&gt; &gt;&gt;standard CSV file in Informix ?<br>
&gt; &gt;&gt;sqlreload doesn't work:<br>
&gt; &gt;&gt;env | grep DB<br>
&gt; &gt;&gt;DBQUOTE=&quot;<br>
&gt; &gt;&gt;DBDELIMITER=,<br>
&gt; &gt;&gt;sqlreload -d db1 -i test1.csv -t test1 -v -x<br>
&gt; &gt;&gt;SQL -846: Number of values in load file is not equal to number
of<br>
&gt; &gt;&gt;columns.<br>
&gt; &gt;&gt;ISAM -746: Too many values in record<br>
&gt; &gt;&gt;It seems, that the comma in double quotes is already identified
as<br>
&gt; &gt;&gt;delimiter...<br>
&gt; &gt;&gt;I have tried with and without an additionally delimiter (comma).<br>
&gt; &gt;&gt;Further suggestions ?<br>
</tt></font>
<br>
<br><font size=2 face="sans-serif">--<br>
Jonathan Leffler (jlef...@us.ibm.com)<br>
STSM, Informix Database Engineering, IBM Information Management Division<br>
4100 Bohannon Drive, Menlo Park, CA 94025<br>
Tel: +1 650-926-6921 &nbsp; Tie-Line: 630-6921<br>
&nbsp; &nbsp; &nbsp;&quot;I don't suffer from insanity; I enjoy every
minute of it!&quot;<br>
</font><font size=2><tt><br>
</tt></font>
--=_alternative 0003511C88256FCD_=--
sending to informix-list

0 new messages