upsert

Postgres upsert using results from select

为君一笑 提交于 2019-12-07 03:35:53
问题 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? 回答1: 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:/

Bulk update/upsert in MongoDB?

三世轮回 提交于 2019-12-06 20:12:30
问题 Is it possible to do bulk update/upsert (not insert) in MongoDB? If yes, please point me to any docs related to this? Thanks 回答1: 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

Check if record exists, if yes “update” if not “insert”

那年仲夏 提交于 2019-12-06 17:02:23
问题 I want to check table PREMIUM_SERVICE_USER if any records exists for strClientID update timeValid for +30 if no records for strClientID insert to premium_service_user table. What am I doing wrong? It increases timeValid for +30 days but inserts another row too. SELECT @pre_var = count(*) FROM PREMIUM_SERVICE_USER WHERE strClientID = @strClientID /* bronze premium - 200 cash */ IF @Premium = 1 BEGIN INSERT INTO PREMIUM_SERVICE_USER (strClientID, timeReg, timeValid, bCurrent, durum) VALUES (

Upsert with $in

大憨熊 提交于 2019-12-06 13:37:41
I want following functionality in MongoDB. I have a collection named 'entities', which basically stores entity text and it's count. The collection looks like this: [{u'_id': u'facebook', u'n': 120}, {u'_id': u'florida', u'n': 98}, {u'_id': u'vegas', u'n': 94}, {u'_id': u'andrew_mason', u'n': 93}, {u'_id': u'obama', u'n': 85}, {u'_id': u'twitter', u'n': 81}, {u'_id': u'outlook', u'n': 81}, {u'_id': u'delhi', u'n': 75}, {u'_id': u'google', u'n': 74}, {u'_id': u'virginia', u'n': 71}] Now, I want to update this collection with new Entities. Basically, I'll have new entities ready in an Array like

IDocumentClient.UpsertDocumentAsync doesn't update, it inserts duplicated ids

别来无恙 提交于 2019-12-06 10:46:49
I have a VS2017 solution in C#, and I'm using IDocumentClient.UpsertDocumentAsync to Upsert some documents into my cosmosdb documentdb collection. But I noticed it's actually creating new documents with the same id while there already is a document in the collection with that id. Now after upserting a new document with the same id the query result looks something like this: select * from c where c.id = "aaaa-bbbb-cccc" [ { "id": "aaaa-bbbb-cccc", "firstname": "john", "lastname": "doe" }, { "id": "aaaa-bbbb-cccc", "firstname": "john", "lastname": "doe", "age": "35" } ] I'm quite confused with

Problems with a PostgreSQL upsert query

假如想象 提交于 2019-12-06 06:36:45
问题 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

mongoDB mongoimport upsert

不打扰是莪最后的温柔 提交于 2019-12-06 05:04:54
问题 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

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

谁都会走 提交于 2019-12-06 03:20:43
问题 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

MongoDB Collection update: initialize a document with default values

浪子不回头ぞ 提交于 2019-12-06 01:05:52
问题 I am trying to deal with time series using MongoDB. The common solution adopted by community is to use subdocuments to store information at different level of granularity (see Schema Design for Time Series Data in MongoDB). For example, take a look at the following document: { timestamp_minute: ISODate("2013-10-10T23:06:00.000Z"), type: “memory_used”, values: [ 999999, // 1 second … 1000000, // nth second 1500000, // n+1th second … 2000000 // 60th ] } The document is indexed by minute

IF-Statement in SQLite: update or insert?

你。 提交于 2019-12-06 00:24:47
问题 I Can't run this query with SQLite if 0<(select COUNT(*) from Repetition where (Word='behnam' and Topic='mine')) begin update Repetition set Counts=1+ (select Counts from Repetition where (Word='behnam' and Topic='mine')) end else begin insert Repetition(Word,Topic,Counts)values('behnam','mine',1) end It says "Syntax error near IF" How can I solve the problem 回答1: SQLite does not have an IF statement (see the list of supported queries) Insetad, check out out ERIC B 's suggestion on another