Rich Shepard wrote:
  When I try to import a data file into an existing table, sqlite's shell
tells me that 31 columns are expected, but it found 32. Now I no longer have the visual acuity I did when I was a teenager, but no matter how many times I count the fields, they total 31. Therefore, I don't know why I'm getting
the error message.

  Here's the table:

CREATE TABLE voting (vote_id INTEGER PRIMARY KEY,
                     cat TEXT, pos TEXT, pr1 REAL, pr2 REAL,
                     pr3 REAL, pr4 REAL, pr5 REAL, pr6 REAL,
                     pr7 REAL, pr8 REAL, pr9 REAL, pr10 REAL,
                     pr11 REAL, pr12 REAL, pr13 REAL,
                     pr14 REAL, pr15 REAL, pr16 REAL,
                     pr17 REAL, pr18 REAL, pr19 REAL,
                     pr20 REAL, pr21 REAL, pr22 REAL,
                     pr23 REAL, pr24 REAL, pr25 REAL,
                     pr26 REAL, pr27 REAL, pr28 REAL);

  And here's the first line of data (I set the .separator to " "):

1 "nat" "pro" 0.500 0.333 3.000 0.167 1.000 1.000 6.000 0.111 0.333 0.333
4.000 6.000 6.000 6.000 8.000 0.143 0.200 8.000 0.200 0.125 0.025 5.000
7.000 0.143 0.111 2.000 0.025 6.000

 What the CLI returns is:

sqlite> .import voting.dat voting
voting.dat line 1: expected 31 columns of data but found 32

  Is there a missing end-of-line terminator? What does sqlite see as the
32nd column?

TIA,

Rich

Rich,

It works just fine for me.

SQLite version 3.3.5
Enter ".help" for instructions
sqlite> CREATE TABLE voting (vote_id INTEGER PRIMARY KEY,
  ...>                      cat TEXT, pos TEXT, pr1 REAL, pr2 REAL,
  ...>                      pr3 REAL, pr4 REAL, pr5 REAL, pr6 REAL,
  ...>                      pr7 REAL, pr8 REAL, pr9 REAL, pr10 REAL,
  ...>                      pr11 REAL, pr12 REAL, pr13 REAL,
  ...>                      pr14 REAL, pr15 REAL, pr16 REAL,
  ...>                      pr17 REAL, pr18 REAL, pr19 REAL,
  ...>                      pr20 REAL, pr21 REAL, pr22 REAL,
  ...>                      pr23 REAL, pr24 REAL, pr25 REAL,
  ...>                      pr26 REAL, pr27 REAL, pr28 REAL);
sqlite> .separator " "
sqlite> .import data.txt voting
sqlite> select * from voting;
1 "nat" "pro" 0.5 0.333 3.0 0.167 1.0 1.0 6.0 0.111 0.333 0.333 4.0 6.0 6.0 6.0
8.0 0.143 0.2 8.0 0.2 0.125 0.025 5.0 7.0 0.143 0.111 2.0 0.025 6.0

Where data.txt contains the line you posted.

1 "nat" "pro" 0.500 0.333 3.000 0.167 1.000 1.000 6.000 0.111 0.333 0.333 4.000 6.000 6.000 6.000 8.000 0.143 0.200 8.000 0.200 0.125 0.025 5.000 7.000 0.143 0.111 2.000 0.025 6.000

I suspect you may have trailing spaces at the ends of your lines. The .import command isn't very smart about things like that. Your separator is set to one space, not arbitrary whitespace. It there is another separator after the last field it assumes there is another field there (which might be an empty string) as well.

HTH
Dennis Cote


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to