upsert

Partial Index not used in ON CONFLICT clause while performing an upsert in Postgresql

余生长醉 提交于 2019-12-18 08:25:26
问题 I have the following Entity Attribute value table : CREATE TABLE key_value_pair ( id serial NOT NULL PRIMARY KEY, key varchar(255) NOT NULL, value varchar(255), is_active boolean ); CREATE UNIQUE INDEX key_value_pair_key_if_is_active_true_unique ON key_value_pair (key) WHERE is_active = true; Sample entries in this table are : id | key | value | is_active ----+-------------+-------+----------- 1 | temperature | 2 | f 2 | temperature | 12 | f 3 | temperature | 15 | f 4 | temperature | 19 | f 5

UPSERT into table with dynamic table name

允我心安 提交于 2019-12-17 20:42:47
问题 Any better method to UPSERT into a table, provided : Data upsert at ~1 row/second Table Name is DYNAMIC, generated using ObjectID parameter passed to it THE FOLLOWING PROCEDURE THROWS : "ORA-00942: table or view does not exist" CREATE OR REPLACE PROCEDURE PROCEDURE "SPINSERTDATA" ( pObjectID IN RAW, pDateTime IN TIMESTAMP, pValue IN BINARY_DOUBLE, ) AS BEGIN Declare vQueryInsert VARCHAR2(1000); vQueryUpdate VARCHAR2(1000); vTableName VARCHAR2(30); Begin vTableName := FGETTABLENAME(POBJECTID =

How to tell if record has changed in Postgres

馋奶兔 提交于 2019-12-17 20:24:38
问题 I have a bit of an "upsert" type of question... but, I want to throw it out there because it's a little bit different than any that I've read on stackoverflow. Basic problem. I'm working on moving from mysql to PostgreSQL 9.1.5 (hosted on Heroku). As a part of that, I need to import multiple CSV files everyday. Some of the data is sales information and is almost guaranteed to be new and need to be inserted. But, other parts of the data is almost guaranteed to be the same. For example, the csv

How to update and upsert multiple documents in MongoDB using C# Drivers

微笑、不失礼 提交于 2019-12-17 19:34:38
问题 I am using MongoDB 2, and I want to update multiple documents and upsert a value like processed:true into the collection. But MongoDB c# api only allows us to either Update Multiple Records or Upsert a single record. How to solve this problem using the C# api? 回答1: After Mongo 2.6 you can do Bulk Updates/Upserts. Example below does bulk update using c# driver. MongoCollection<foo> collection = database.GetCollection<foo>(collectionName); var bulk = collection.InitializeUnorderedBulkOperation(

MySQL “good” way to insert a row if not found, or update it if it is found

巧了我就是萌 提交于 2019-12-17 17:59:36
问题 Very often, I want to run a query on one of my users where I want a row stored and associated with that user, in a 1-to-1 relationship. So let's say (this is just an arbitrary example), that I have a table that keeps track of a user's car, along with some info about the car. Each user can have either 0 or 1 cars. If the user has no car, there is no entry in the table for that user. cars table (again, just an example): id, user_id, car_make, car_model So, when I update this table, I always end

How do I update if exists, insert if not (AKA “upsert” or “merge”) in MySQL?

风流意气都作罢 提交于 2019-12-16 19:17:12
问题 Is there an easy way to INSERT a row when it does not exist, or to UPDATE if it exists, using one MySQL query? 回答1: Yes, INSERT ... ON DUPLICATE KEY UPDATE. For example: INSERT INTO `usage` (`thing_id`, `times_used`, `first_time_used`) VALUES (4815162342, 1, NOW()) ON DUPLICATE KEY UPDATE `times_used` = `times_used` + 1 回答2: I know this is an old question, but the Google lead me here recently so I imagine others come here, too. @chaos is correct: there is the INSERT ... ON DUPLICATE KEY

Issue with a simple mongo/monk findAndModify query

拜拜、爱过 提交于 2019-12-13 18:41:12
问题 Just a note I am fairly new to mongo and more notably very new to using node/js. I'm trying to write a query to insert new documents or update already existing documents in my collection. The proposed structure of the collection is: { _id: xxxxxxx, ip: "xxx.xxx.xxx.xxx:xxxxxx", date: "xx-xx-xx xxxx" } Note that my intention is a store an fixed length int for the _id rather than the internal ObjectId (is this possible/considered bad practice?). The int is guaranteed to be unique and comes from

SQL Server, How to remove updates elements from User-Defined Table Type?

社会主义新天地 提交于 2019-12-13 16:13:10
问题 I have a User-Defined Table Type, lets say @TT dbo.IntType readonly, IntType is batch of int , as Primary-Key CREATE TYPE [dbo].[IntType] AS TABLE( [T] [int] NOT NULL, PRIMARY KEY CLUSTERED I like to do UPDATE based on all key( int ) in IntType , and INSERT new rows for the key( int ) not exist in the database (an upsert) I wonder if theres a easy way to remove the "UPDATED" key( int )? Then I can insert the rest. (or if you have a super one-line upsert for SQL Server 2010!!!) 回答1: Use the

Can I use MERGE INTO to simulate “upsert” in Apache Derby?

时间秒杀一切 提交于 2019-12-13 13:34:34
问题 We're using Derby and have a lot of code which goes like this: try (ResultSet rs = executeQuery(...)) { if (rs.next()) { updateRowSet(rs, ...); rs.updateRow(); } else { executeUpdate(...); } } In the past, we were searching for a way to do this logic server-side, and found that some databases supported an "upsert" (update or insert) operation. Derby had a feature request for MERGE INTO which was supposedly the SQL:2003 standard way of doing this, so we sat and watched the ticket, and much

Upsert many records using ReactiveMongo and Scala

三世轮回 提交于 2019-12-12 18:42:16
问题 I am writing a DAO Actor for MongoDB that uses ReactiveMongo. I want to implement some very simple CRUD operations, among which the ability to upsert many records in one shot. Since I have a reactive application (built on Akka), it's important for me to have idempotent actions, so I need the operation to be an upsert, not an insert. So far I have the following (ugly) code to do so: case class UpsertResult[T](nUpd: Int, nIns: Int, failed: List[T]) def upsertMany[T](l: List[T], collection: