Giter VIP home page Giter VIP logo

Comments (4)

andrus avatar andrus commented on May 23, 2024

Did some research on the existing DB / JDBC capabilities. TL;DR: none of them seem to fully address what we need.

  1. DB "UPSERT" syntax: Some DBs support explicit syntax for it as a part of the INSERT clause (MySQL, PostgreSQL, SQLServer, Oracle, Derby) , though it only works when we are merging on explicit PK.

  2. Updatable ResultSet. Tried it on MySQL (see below). Unfortunately this generates 2 operations per updated row (INSERT/UPDATE + SELECT). So this seems to be intended for GUI data editors, not for bulk operations.

String sql = "SELECT id, name FROM test";
try (PreparedStatement st = c.prepareStatement(
        sql,
        ResultSet.TYPE_SCROLL_SENSITIVE,
        ResultSet.CONCUR_UPDATABLE)) {

    try (ResultSet rs = st.executeQuery()) {

        while (rs.next()) {
            String name = rs.getString(2);
            rs.updateString(2, name + "1");
            rs.updateRow();
        }

        rs.moveToInsertRow();
        rs.updateLong(1, new Random().nextLong());
        rs.updateString(2, "inserted");
        rs.insertRow();
    }
}

from dflib.

andrus avatar andrus commented on May 23, 2024

"UPSERT" operation is done. Current shortcomings of the UPDATE part:

  1. We update rows that haven't changed
  2. We update all non-key columns, not just the ones that have changed

from dflib.

andrus avatar andrus commented on May 23, 2024

Done skipping unchanged rows

from dflib.

andrus avatar andrus commented on May 23, 2024

Done organizing by UPDATE columns

from dflib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.