GithubHelp home page GithubHelp logo

Comments (6)

samdark avatar samdark commented on May 27, 2024

Looks like a good idea. Further research on how to do it in MSSQL, Oracle and SQLite is needed to move forward to implementing it.

from db.

bscheshirwork avatar bscheshirwork commented on May 27, 2024

@dimmitri good idea. So... I see some indeterminate stages: how to get inserted ids? How to separate inserted and updated rows?

from db.

dimmitri avatar dimmitri commented on May 27, 2024

I think it is necessary to first look at ALL the options implemented in different DBMS. To identify common features. In PostgreSQL in at least two ways to do it, in MySQL I know of one, but maybe more of them. I've never used MSSQL, Oracle and SQLite.

How to separate inserted and updated rows?

PostgreSQL. In this case, for example, insert is not happening:

UPDATE table AS t
SET
    col1 = c.col1,
    col2 = c.col2
FROM (VALUES (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4) ) AS c (id, col1, col2)
WHERE c.id = t.id;

from db.

Vovan-VE avatar Vovan-VE commented on May 27, 2024

in MySQL I know of one, but maybe more of them

In MySQL UPDATE with JOIN can be used for example. Something like this:

UPDATE `table` AS `t` 
    JOIN (
        SELECT 1 AS `id`, 1 AS `col1`, 1 AS `col2`
        UNION SELECT 2, 2, 2
        UNION SELECT 3, 3, 3
    ) AS `c`
        ON `t`.`id` = `c`.`id`
SET
    `t`.`col1` = `c`.`col1`,
    `t`.`col2` = `c`.`col2`;

from db.

bscheshirwork avatar bscheshirwork commented on May 27, 2024

@Vovan-VE
i.e. need
n subquery + 1 query
vs
n query
if you can directly update row-by-row?

from db.

Tigrov avatar Tigrov commented on May 27, 2024

Related with #67 perhaps double.
Looks like need batchUpsert() for both issues.

from db.

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.