upsert

How do I do batch upserts in SQL Server?

那年仲夏 提交于 2019-12-05 23:13:30
I'm using the MERGE statement to upsert rows in an sql server 2008 database. However, my sproc is a single-row operation, whereas in fact I'd prefer to batch these. Is this even possible and, if so, how do I do it? Can you use Table-Valued Parameters in your proc? Take a look here http://www.sommarskog.se/arrays-in-sql-2008.html#TVP_in_TSQL to get some ideas Then in the proc you can use MERGE against the TVP i have created a proc called 'upsert' which takes a source table name, target table name, fields to join on, and fields to update (fields are separated by commas) and then does the merge

Upsert (update or insert) in Sybase ASE?

时光总嘲笑我的痴心妄想 提交于 2019-12-05 20:01:43
问题 I'm writing an application to move data from Oracle to Sybase and need to perform update / insert operations. In Oracle, I'd use MERGE INTO, but it doesn't seem to be available in Sybase (not in ASE, anyway). I know this can be done with multiple statements, but for a couple of reasons, I'm really trying to get this into a single statement. Any suggestions? 回答1: ASE 15.7 has this feature. Find the docs here: http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc36272.1570/html

Mysql on duplicate key update + sub query

女生的网名这么多〃 提交于 2019-12-05 08:26:31
Using the answer from this question: Need MySQL INSERT - SELECT query for tables with millions of records new_table * date * record_id (pk) * data_field INSERT INTO new_table (date,record_id,data_field) SELECT date, record_id, data_field FROM old_table ON DUPLICATE KEY UPDATE date=old_table.data, data_field=old_table.data_field; I need this to work with a group by and join.. so to edit: INSERT INTO new_table (date,record_id,data_field,value) SELECT date, record_id, data_field, SUM(other_table.value) as value FROM old_table JOIN other_table USING(record_id) GROUP BY record_id ON DUPLICATE KEY

Postgres upsert using results from select

青春壹個敷衍的年華 提交于 2019-12-05 06:45:49
I'm trying to upsert with postgres using values from a select. It looks like: INSERT INTO foo (a, b, c) SELECT a_, b_, c_ -- hairy sql ON CONFLICT (...condition...) DO UPDATE SET "c"=??? On conflict, I want to use one of the values from my select statement, but I can't find the right syntax to alias it. How can I do this with Postgres? Use the excluded keyword: INSERT INTO foo (a, b, c) SELECT a_, b_, c_ -- hairy sql ON CONFLICT (...condition...) DO UPDATE SET c = excluded.c; 来源: https://stackoverflow.com/questions/44466232/postgres-upsert-using-results-from-select

MongoDB: update dictionary in document

南楼画角 提交于 2019-12-05 04:36:28
I have a MongoDB document that saves occurrences of some things in a dictionary: { "id" : 1, "occurrences" : { "1" : 1, "2" : 5, "17" : 1, "35" : 4 } } I now want to add or update some entries, for example add a "12:3" to the occurrences, or update the number of occurrences of "17" to 2, so let's say as an example I want to add {"12":3} and {"17":2} to this dictionary. It is driving me crazy because I simply can not get it to work. I could use arrays and all that, but I would really like to have it in this particular design. Any ideas on how to solve this? I tried so many different things with

Bulk update/upsert in MongoDB?

萝らか妹 提交于 2019-12-05 01:40:25
Is it possible to do bulk update/upsert (not insert) in MongoDB? If yes, please point me to any docs related to this? Thanks You can use the command line program mongoimport it should be in your MongoDB bin dir ... There are two options you'll want to look into to use upsert ... --upsert insert or update objects that already exist --upsertFields arg comma-separated fields for the query part of the upsert. You should make sure this is indexed More info here: http://www.mongodb.org/display/DOCS/Import+Export+Tools Or just do ... $ mongoimport --help unique mongo can execute .js file. you can

Meteor Allow Upsert?

孤街醉人 提交于 2019-12-04 23:00:30
问题 Getting this error in the console when I try upserting to a collection: "update failed: Access denied. Upserts not allowed in a restricted collection." Here are the allow rules I've specified: if (Meteor.isClient) { Meteor.subscribe('customers'); } customers = Customers if (Meteor.isServer) { Meteor.publish('customers', function() { return customers.find(); }); customers.allow({ insert: function (document) { return true; }, update: function () { return true; }, remove: function () { return

Problems with a PostgreSQL upsert query

喜你入骨 提交于 2019-12-04 14:33:15
I'm trying to update the database by either updating or inserting a new record into the vote_user_table . The table is defined as follows: Column | Type | Modifiers -----------+---------+-------------------------------------------------------------- id | integer | not null default nextval('vote_user_table_id_seq'::regclass) review_id | integer | not null user_id | integer | not null positive | boolean | default false negative | boolean | default false Indexes: "vote_user_table_pkey" PRIMARY KEY, btree (id) Here's the query I'm using. I'm actually using parameters for all of the values, but for

mongoDB mongoimport upsert

允我心安 提交于 2019-12-04 11:26:37
I'm trying to do a bulk update with the following mongoimport -d my_db -c db_collection -upsertFields email ~/Desktop/update_list.csv the csv that i'm trying to import looks like this. email, full_name stack@overflow.com,stackoverflow mongo@db.com,mongodb It should check the email column as a query arg and update the full name accordingly. However, none were imported, it encountered errors. exception:Failure parsing JSON string near: abc@sa abc@sasa.com,abc imported 0 objects encountered 99398 errors Where is the problem? How should i be doing it? Your mongoimport command is missing the -

What is the most efficient / best practise to Upsert 5000+ rows without Merge in SQL Server?

ε祈祈猫儿з 提交于 2019-12-04 08:42:05
I have a web application which receives about 50 hits per second, and on each hit I am upsert'ing around 10 records in a central SQL Server database. Roughly once every 3 seconds I am upserting 5000+ rows for a single inbound connection. Currently I have a stored procedure which takes XML as a parameter. I do an INSERT into my main table from my XML where a row field doesn't match, then update the whole table with values from my XML. The operation isn't slow by any means, but I really would like to know the best way to do this. I am running on SQL Server 2005 so I don't have the MERGE