upsert

How to resolve SQL0418N Error

≡放荡痞女 提交于 2019-11-27 05:36:32
I'm using the statement below to update/insert some data to a table and, if I run it without parameters, it's fine. However, as soon as I try to execute it using parameters it throws: SQL0418N - A statement contains a use of an untyped parameter marker, the DEFAULT keyword, or a null value that is not valid . I've read the error information here , but I'm still struggling with why my statement won't execute. --This statement works MERGE Into AB.Testing_Table A USING (VALUES('TEST', 'P')) B(TEST_ID, "ACTION") ON (A.TEST_ID = B.TEST_ID) WHEN NOT MATCHED THEN INSERT (TEST_ID, "ACTION") VALUES (

Upsert Array Elements matching criteria in a MongoDB document?

帅比萌擦擦* 提交于 2019-11-27 04:42:47
问题 As per How do I update Array Elements matching criteria in a MongoDB document? I want to upsert the array elements, so if one doesnt match then insert it, otherwise update it. I tried the answer on that question, and it works fine IF the array element already exists. If the element doesnt exist then it creates a child of "$" under the array field. My Mongo structure is as follows: Widget (collection) --Name --Properties (array) --Name --Value My application gets a Widget Name and a list of

mongodb - create doc if not exist, else push to array

时光怂恿深爱的人放手 提交于 2019-11-27 03:55:23
问题 I have a document in the following form: { "_id" : ObjectId("4d2d8deff4e6c1d71fc29a07"), "user_id" : "714638ba-2e08-2168-2b99-00002f3d43c0", "events" : [ { "profile" : 10, "data" : "....." } { "profile" : 10, "data" : "....." } { "profile" : 20, "data" : "....." } ... ] } I'd like to have some sort of upsert statement. It needs to add an event to the events array for user_id in case there is already such doc exist, else it needs to create the doc with the event item. Can that be done? 回答1:

Use multiple conflict_target in ON CONFLICT clause

霸气de小男生 提交于 2019-11-27 01:00:47
问题 I have two columns in table col1 , col2 , they both are unique indexed (col1 is unique and so is col2). I need at insert into this table, use ON CONFLICT syntax and update other columns, but I can't use both column in conflict_target clause. It works: INSERT INTO table ... ON CONFLICT ( col1 ) DO UPDATE SET -- update needed columns here But how to do this for several columns, something like this: ... ON CONFLICT ( col1, col2 ) DO UPDATE SET .... 回答1: A sample table and data CREATE TABLE dupes

syntax for single row MERGE / upsert in SQL Server

Deadly 提交于 2019-11-27 00:34:37
I'm trying to do a single row insert/update on a table but all the examples out there are for sets. Can anyone fix my syntax please: MERGE member_topic ON mt_member = 0 AND mt_topic = 110 WHEN MATCHED THEN UPDATE SET mt_notes = 'test' WHEN NOT MATCHED THEN INSERT (mt_member, mt_topic, mt_notes) VALUES (0, 110, 'test') Resolution per marc_s is to convert the single row to a subquery - which makes me think the MERGE command is not really intended for single row upserts. MERGE member_topic USING (SELECT 0 mt_member, 110 mt_topic) as source ON member_topic.mt_member = source.mt_member AND member

Elasticsearch upserting and appending to array

让人想犯罪 __ 提交于 2019-11-27 00:29:55
问题 I'm trying to write a script that will upsert a new user record to ElasticSearch, updating any information if the user already exists, and appending a new PaymentInfo object to the user's Payments array if it exists in the update object. Here's a simplified version of what I'm working with so far: curl -XPOST 'http://localhost:9200/usrtest/usr/1/_update' -d ' { "doc_as_upsert": true, "doc": { "customerId": "1", "firstName": "Mark", "lastName": "Z", "emailAddress": "foo.bar@gmail.com",

Oracle: ON DUPLICATE KEY UPDATE [duplicate]

ぃ、小莉子 提交于 2019-11-26 22:05:32
问题 This question already has an answer here: Oracle: how to UPSERT (update or insert into a table?) 12 answers I'm trying to implement a solution I found over here from Michiel de Mare to update multiple records with one (preferably-simple-in-a-syntax-sense) query. The example code that I am trying to learn from looks like this: INSERT INTO table (id,Col1,Col2) VALUES (1,1,1),(2,2,3),(3,9,3),(4,10,12) ON DUPLICATE KEY UPDATE Col1=VALUES(Col1),Col2=VALUES(Col2); I'm using Oracle (and am not yet

How do I UPDATE a row in a table or INSERT it if it doesn't exist?

删除回忆录丶 提交于 2019-11-26 21:41:41
I have the following table of counters: CREATE TABLE cache ( key text PRIMARY KEY, generation int ); I would like to increment one of the counters, or set it to zero if the corresponding row doesn't exist yet. Is there a way to do this without concurrency issues in standard SQL? The operation is sometimes part of a transaction, sometimes separate. The SQL must run unmodified on SQLite, PostgreSQL and MySQL, if possible. A search yielded several ideas which either suffer from concurrency issues, or are specific to a database: Try to INSERT a new row, and UPDATE if there was an error.

Is MERGE an atomic statement in SQL2008?

偶尔善良 提交于 2019-11-26 21:32:33
问题 I am using a MERGE statement as an UPSERT to either add a new record or update the current one. I have multiple threads driving the database through multiple connections and multiple statements (one connection and statement per thread). I am batching the statements 50 at a time. I was very surprised to get a duplicate key violation during my tests. I expected that to be impossible because the MERGE will be performed as a single transaction, or is it? My Java code looks like: private void

How to find out if an upsert was an update with PostgreSQL 9.5+ UPSERT?

萝らか妹 提交于 2019-11-26 20:55:42
问题 Writable CTEs were considered a solution to UPSERT prior to 9.5 as described in Insert, on duplicate update in PostgreSQL? It is possible to perform an UPSERT with the information whether it ended up as an UPDATE or an INSERT with the following Writable CTEs idiom: WITH update_cte AS ( UPDATE t SET v = $1 WHERE id = $2 RETURNING 'updated'::text status ), insert_cte AS ( INSERT INTO t(id, v) SELECT $2, $1 WHERE NOT EXISTS (SELECT 1 FROM update_cte) RETURNING 'inserted'::text status ) (SELECT