On 14 October 2011 15:17, James Hartley <[email protected]> wrote:
> When attempting to import CSV data, the shell balks at the command-line but
> is otherwise fine when all is done interactively. I suspect user error, but
> I just don't see it. Any insight shared would be greatly appreciated.
I am using wdoze not *nix, but it may be that your -separator gives
different result to .separator...
>
> Thanks.
>
> $ ls
> create_table.sql src.csv
> $ cat create_table.sql
> src.csv <
> CREATE TABLE staging(
> number TEXT,
> first_string TEXT,
> second_string TEXT,
> third_string TEXT
> );
> 1,two,three,four
> 2,three,four,five
> $ sqlite3 db '.read create_table.sql'
> $ sqlite3 -separator '",' db '.import src.csv staging'
why not
$ sqlite3 -separator ',' db '.import src.csv staging' ?
on my m/c I have to use
sqlite3 -separator "," db ".import src.csv staging"
but it then works with no error
To test, try
$ sqlite3 -separator '",' db
.show
.separator ",
.show
and look at what the separator is set to in the .show output...
> Error: src.csv line 1: expected 4 columns of data but found 1
> $ rm db
> $ sqlite3 db
> SQLite version 3.7.5
> Enter ".help" for instructions
> Enter SQL statements terminated with a ";"
> sqlite> .read create_table.sql
> sqlite> .separator ",
> sqlite> .import src.csv staging
> sqlite> .separator |
> sqlite> select * from staging;
> 1|two|three|four
> 2|three|four|five
> sqlite> .q
> $
Regards,
Simon
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users