upsert

If Record Exists, Update Else Insert

北战南征 提交于 2019-11-30 23:23:29
问题 I'm trying to move some data between two SQL Server 2008 tables. If the record exists in Table2 with the email from Table1 then update that record with the data from Table1, else insert a new record. In Table1 I have a number of columns; first name, surname, email and so on. I'm not quite sure how to structure the query to update Table2 if the email from Table1 exists or insert a new row if email from Table1 does not exist in Table2. I tried doing a few searches on Google but most solutions

Postgresql - Clean way to insert records if they don't exist, update if they do

◇◆丶佛笑我妖孽 提交于 2019-11-30 22:33:41
Here's my situation. I have a table with a bunch of URLs and crawl dates associated with them. When my program processes a URL, I want to INSERT a new row with a crawl date. If the URL already exists, I want to update the crawl date to the current datetime. With MS SQL or Oracle I'd probably use a MERGE command for this. With mySQL I'd probably use the ON DUPLICATE KEY UPDATE syntax. I could do multiple queries in my program, which may or may not be thread safe. I could write a SQL function which has various IF...ELSE logic. However, for the sake of trying out Postgres features I've never used

Add or replace entity in Azure Table Storage

倾然丶 夕夏残阳落幕 提交于 2019-11-30 22:16:57
问题 I'm working with Windows Azure Table Storage and have a simple requirement: add a new row, overwriting any existing row with that PartitionKey/RowKey. However, saving the changes always throws an exception, even if I pass in the ReplaceOnUpdate option: tableServiceContext.AddObject(TableName, entity); tableServiceContext.SaveChangesWithRetries(SaveChangesOptions.ReplaceOnUpdate); If the entity already exists it throws: System.Data.Services.Client.DataServiceRequestException: An error occurred

Upsert Multiple Records with MongoDb

一个人想着一个人 提交于 2019-11-30 20:48:20
I'm trying to get MongoDB to upsert multiple records with the following query, ultimately using MongoMapper and the Mongo ruby driver. db.foo.update({event_id: { $in: [1,2]}}, {$inc: {visit:1}}, true, true) This works fine if all the records exist, but does not create new records for records that do not exist. The following command has the desired effect from the shell, but is probably not ideal from the ruby driver. [1,2].forEach(function(id) {db.foo.update({event_id: id}, {$inc: {visit:1}}, true, true) }); I could loop through each id I want to insert from within ruby, but that would

MongoDb upsert exception invalid BSON field

限于喜欢 提交于 2019-11-30 20:39:59
This exception: Exception in thread "Thread-1" java.lang.IllegalArgumentException: Invalid BSON field name id at org.bson.AbstractBsonWriter.writeName(AbstractBsonWriter.java:516) at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:188) at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:131) at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:45) at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63) at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:29) at com.mongodb.connection.UpdateCommandMessage

AddOrUpdate works not as expected and produces duplicates

拜拜、爱过 提交于 2019-11-30 17:12:05
I'm using Code-First DBContext-based EF5 setup. In DbMigrationsConfiguration.Seed I'm trying to fill DB with default dummy data. To accomplish this task, I use DbSet.AddOrUpdate method. The simplest code to illustrate my aim: j = 0; var cities = new[] { "Berlin", "Vienna", "London", "Bristol", "Rome", "Stockholm", "Oslo", "Helsinki", "Amsterdam", "Dublin" }; var cityObjects = new City[cities.Length]; foreach (string c in cities) { int id = r.NextDouble() > 0.5 ? 0 : 1; var city = new City { Id = j, Name = c, Slug = c.ToLowerInvariant(), Region = regions[id], RegionId = regions[id].Id, Reviewed

UPSERT in SSIS

倾然丶 夕夏残阳落幕 提交于 2019-11-30 14:42:39
I am writing an SSIS package to run on SQL Server 2008. How do you do an UPSERT in SSIS? IF KEY NOT EXISTS INSERT ELSE IF DATA CHANGED UPDATE ENDIF ENDIF See SQL Server 2008 - Using Merge From SSIS . I've implemented something like this, and it was very easy. Just using the BOL page Inserting, Updating, and Deleting Data using MERGE was enough to get me going. Arnkrishn I would suggest you to have a look at Mat Stephen's weblog on SQL Server's upsert. SQL 2005 - UPSERT: In nature but not by name; but at last! Raj The basic Data Manipulation Language (DML) commands that have been in use over

Bulk Upsert with MongoDB Java 3.0 Driver

可紊 提交于 2019-11-30 12:13:54
问题 In the earlier versions of MongoDB Java drivers , to run a query and do unordered bulk upsert on the result all we had do was : BulkWriteOperation bulk = dbCollection.initializeUnorderedBulkOperation(); bulk.find(searchQuery).upsert().update(new BasicDBObject("$set", getDbObjectModel())); But in version 3, with the introduction of Bson Document support and MongoCollection.bulkWrite() method how can this be done? I tried this : List<WriteModel<Document>> documentList = new ArrayList<>();

Meteor upsert equivalent

可紊 提交于 2019-11-30 09:57:49
How soon will the upsert command be implemented in Meteor? And, what is the best way to do the same thing in the mean time? Something like this is what I'm doing at the moment: if typeof ( item = Items.findOne({title:'Foo'}) ) == 'undefined' item = Items.insert({title:'Foo'}) else Items.update(item._id, {$set: {title:'Foo'}}) # do something with item alanning How soon will the upsert command be implemented in Meteor? UPDATE: @Thomas4019 points out that upsert is now supported: v0.6.6 "Add upsert support. Collection.update now supports the {upsert: true} option. Additionally, add a Collection

Mongodb upsert only update selected fields, but insert all

两盒软妹~` 提交于 2019-11-30 09:03:34
I am trying to use upsert in MongoDB to update a single field in a document if found OR insert a whole new document with lots of fields. The problem is that it appears to me that MongoDB either replaces every field or inserts a subset of fields in its upsert operation, i.e. it can not insert more fields than it actually wants to update. What I want to do is the following: I query for a single unique value If a document already exists, only a timestamp value (lets call it 'lastseen') is updated to a new value If a document does not exists, I will add it with a long list of different key/value