I have changeset to loading a csv to the database. I am using loadUpdateData tag so that any changes to the csv are handled automatically without having to write a new changeset. In the loadUpdateData, i specify the "primaryKey" field, which is different from the actual primary key on the table. This works fine for oracle, but fails for mysql.
My changeset looks like this
- <changeSet author ="abc" id="db-1" runAlways="true">
- <loadUpdateData primaryKey="Col10" tablename="someTable" file="changelog/someTable.csv">
- <column name="Col2" type="DATE"/>
- .
- .
- </loadUpdateData>
- </changeSet>
The primary key on the table "someTable" is a column named "Col1" which is auto-generated
The oracle generated sql file is
- DECLARE
- v_reccount NUMBER := 0;
- BEGIN
- SELECT COUNT(*) INTO v_reccount FROM someTable WHERE FIELDNAME = 'Col10';
- IF v_reccount = 0 THEN
- INSERT INTO someTable (...) VALUES (...);
- ELSIF v_reccount = 1 THEN
- UPDATE someTable SET Col2="31-DEC-2019" WHERE FIELDNAME = 'Col10';
- END IF;
- END;
- /
However, the one generated for mysql looks like
- INSERT INTO someTable () VALUES ()
- ON DUPLICATE KEY Col2=..., Col3=...;
So, why does the mysql generated statement assume that I want to update data based on the primary key defined in the table, not the column name provided in the primaryKey parameter in the changeSet?