FAQ Database Discussion Community


Upsert on a range

sql-server-2008,upsert
I'm aware of this: IF EXISTS (SELECT * FROM table WHERE pk = @pk) BEGIN --Update END ELSE BEGIN --INSERT END But this works for one row. Let's say I have a table min_max M and a temp table __MinMaxImport T. I want to INSERT from T to M, but...

SQL Insert when not exist where dataset is from select query

sql,sql-server,sql-server-2008,upsert
I am trying to execute following query INSERT INTO MyTable(Column1, Column2) SELECT Column1Value, 'Temp' -- This will return multiple values which are to be inserted. FROM Table2 t2 INNER JOIN Table3 t3 ON t2.Column1 = t3.Column1 ... Few more joins ... WHERE t2.Column3 = 0 As you can see in...

MySQL “UPSERT” and delete not affected rows

mysql,performance,delete,upsert
I have a table in MySQL that is updated every night with a cron task. Every row is altered, because I'm getting the data from a XLS file and have to update all values. At first my question was if it worth updating each row or on the other hand...

Couchbase Bulk loading error with upsert() (.NET SDK 2.0)

c#,.net,collections,couchbase,upsert
I have encountering an error when inserting bulk data with the upsert function and cannot figure out how to fix it. Anyone know what is wrong here? What the program is essentially doing is grabbing data from a SQL server database and loading into our Couchbase bucket on an Amazon...

What happens with duplicates when inserting multiple rows?

sql,postgresql,exception,duplicates,upsert
I am running a python script that inserts a large amount of data into a Postgres database, I use a single query to perform multiple row inserts: INSERT INTO table (col1,col2) VALUES ('v1','v2'),('v3','v4') ... etc I was wondering what would happen if it hits a duplicate key for the insert....

How can I refer to a variable in postgresql dynamic SQL?

sql,postgresql,dynamic,upsert
I'm trying to write a PostgreSQL function for table upserts that can be used for any table. My starting point is taken from a concrete function for a specific table type: CREATE TABLE doodad(id BIGINT PRIMARY KEY, data JSON); CREATE OR REPLACE FUNCTION upsert_doodad(d doodad) RETURNS VOID AS $BODY$ BEGIN...

changing meteor restivus PUT to implement upsert

api,rest,meteor,upsert
i'm using restivus with meteor and would like to change the PUT schemantic to an upsert. // config rest endpoints Restivus.configure({ useAuth: false, prettyJson: false }); Restivus.addCollection("sensor", { excludedEndpoints: ['getAll','deleteAll','delete'], defaultOptions: {}, }); how does one do this?...

How can I perform an UPSERT using Azure DocumentDB?

azure,upsert,azure-documentdb
Azure DocumentDB does not support UPSERT. Is there a reasonable work around to achieve the same functionality? Is using a stored procedure which checks if the document exists to determine whether and insert or update should be performed an effective strategy? What if I need to perform thousands of these...

How to optimize MERGE using multiple column index

sql-server-2008,merge,upsert
I'm new to MERGE and an index novice so bear with me... I have a stored procedure that builds a #changes temp table, UPDATEs a prod_tbl table based on #changes, then INSERTs the before and after values into auto_update_log table that is quickly growing with duplicate rows. In order to...

Loopback return an existing record on PU/UPSERT

postgresql,loopbackjs,upsert
I have the following PostGreSQL Locations table: -------------------- | ID | Name | -------------------- | 1 | Kitchen | -------------------- | 2 | Bedroom1 | -------------------- ID is a sequential PQ and Name has a unique constraint. Locations.json Name property has "index": { "unique": true }, And Locations.js includes Location.validatesUniquenessOf('Name');...

Python peewee save() doesn't work as expected

python,mysql,upsert,peewee
I'm inserting/updating objects into a MySQL database using the peewee ORM for Python. I have a model like this: class Person(Model): person_id = CharField(primary_key=True) name = CharField() I create the objects/rows with a loop, and each time through the loop have a dictionary like: pd = {"name":"Alice","person_id":"A123456"} Then I try...