Quantcast
Channel: Liquibase Forums
Viewing all articles
Browse latest Browse all 1169

loadupdatedata behavior for mysql

$
0
0
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
  1. <changeSet author ="abc" id="db-1" runAlways="true">
  2.     <loadUpdateData primaryKey="Col10" tablename="someTable" file="changelog/someTable.csv">
  3.       <column name="Col2" type="DATE"/>
  4.       .
  5.       .
  6.      </loadUpdateData>
  7. </changeSet>

The primary key on the table "someTable" is a column named "Col1" which is auto-generated

The oracle generated sql file is
  1. DECLARE
  2. v_reccount NUMBER := 0;
  3. BEGIN
  4. SELECT COUNT(*) INTO v_reccount FROM someTable WHERE FIELDNAME = 'Col10';
  5. IF v_reccount = 0 THEN
  6. INSERT INTO someTable (...) VALUES (...);
  7. ELSIF v_reccount = 1 THEN
  8. UPDATE someTable SET Col2="31-DEC-2019" WHERE FIELDNAME = 'Col10';
  9. END IF;
  10. END;
  11. /
However, the one generated for mysql looks like 
  1. INSERT INTO someTable () VALUES ()
  2. 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?

Viewing all articles
Browse latest Browse all 1169

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>