I’m trying to export data from SPSS (Statistics program) to a local mysql database. For some reason i’m getting the ‘Column count doesn’t match value count’ message. I’m used to getting that error when something in the SQL statement is wrong. But after hours of testing in a lot of different setting, it’s clear that that is not the problem.
SPSS syntax is in SQL. The syntax that will work is for example this one:
SAVE TRANSLATE /TYPE=ODBC
/CONNECT='DSN=localhost;UID=root;PWD=!S%E&u#k;'
/ENCRYPTED
/MISSING=IGNORE
/SQL='CREATE TABLE test1 (jaar double , maand double , dag double , huishoud double , persoon double , verpl double , rit double )'
/REPLACE
/TABLE='SPSS_TEMP_2'
/KEEP=jaar, maand, dag, huishoud, persoon, verpl, rit
/SQL='INSERT INTO test1 (jaar, maand, dag, huishoud, persoon, verpl, rit) SELECT jaar, maand, dag, huishoud, persoon, verpl, rit FROM SPSS_TEMP_2'
/SQL='DROP TABLE SPSS_TEMP_2'.
After running this command the mysql database looks like this:
CREATE TABLE `test1` (
`jaar` double DEFAULT NULL,
`maand` double DEFAULT NULL,
`dag` double DEFAULT NULL,
`huishoud` double DEFAULT NULL,
`persoon` double DEFAULT NULL,
`verpl` double DEFAULT NULL,
`rit` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
With the following data:
INSERT INTO `test1` (`jaar`, `maand`, `dag`, `huishoud`, `persoon`, `verpl`, `rit`) VALUES
(2005, 1, 3, 1, 1, 1, 1),
(2005, 1, 3, 0, 0, 1, 1),
(2005, 1, 3, 1, 1, 1, 1),
(2005, 1, 3, 0, 0, 1, 1),
(2005, 1, 3, 0, 0, 1, 1),
(2005, 1, 3, 0, 0, 1, 1),
(2005, 1, 3, 0, 1, 1, 1),
(2005, 1, 3, 0, 0, 1, 1),
(2005, 1, 3, 0, 0, 1, 1),
(2005, 1, 3, 0, 0, 1, 1);
So far so good. However, the complete dataset comes with 129 variables (sql fields). The first one that gives a error is called ‘ritid’. When it is inserted along with others, it stops the complete process. But even when inserted alone, it breaks. It creates the table but without any data. As seen below. I’t is strange to me that this type of error shows up. Someone able to give some word of advice?
SAVE TRANSLATE /TYPE=ODBC
/CONNECT='DSN=localhost;UID=root;PWD=!l*z%J,[;'
/ENCRYPTED
/MISSING=IGNORE
/SQL='CREATE TABLE Test2 (ritid double )'
/REPLACE
/TABLE='SPSS_TEMP_2'
/KEEP=ritid
/SQL='INSERT INTO Test2 (ritid) SELECT ritid FROM SPSS_TEMP_2'
/SQL='DROP TABLE SPSS_TEMP_2'.
>Error # 6491. Text: Case #1 has been dropped
>Insert record failed
>Execution of this command stops.
>[Actual][MySQL] Column count doesn't match value count at row 1
>Error # 6487
>Write request failed - couldn't write any data.
The mysql DB:
CREATE TABLE `Test2` (
`ritid` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
(as said before, no data is present in this one)
EDIT:
When skipping the ‘drop SPSS_TEMP_2’ command, the SPSS_TEMP_2 database turns out exactly the same as the Test2 database.
Finally I found the solution, with a nice hint from IBM Support.
There two variables in SPSS (fields in SQL) that are causing the trouble. They are ‘ritid’ and ‘hhid’. When viewed in SPSS, there values occur as numbers without any dot or comma. When exported as a .csv file, there still not showing any problem, although they .csv file does report the same SQL error when importing through mysql.
But when saving the SPSS file as a .dbf file and opening in FileMaker Pro, the exact same variables are shown as a values with a comma after the first character. There should be one though; the nature of the data doesn’t want one over there. But still…
To make the export from SPSS to mysql possible, I changed the ‘type’ field of the variables in SPSS to ‘type=string’ instead of ‘type=numeric’. That makes the export possible.
Still, there are a couple of things to think about. For instance, exporting them this way has some implications for importing them back again, since they tend to do contain a comma. But that’s easily to cath by editing the sql data in mysql with PHP.
Thanks for all the suggestions!