All Questions

486
votes
16answers
294864 views

Insert, on duplicate update in PostgreSQL?

Several months ago I learned from an answer on Stack Overflow how to perform multiple updates at once in MySQL using the following syntax: INSERT INTO table (id, field, field2) VALUES (1, A, X), (2, ...
182
votes
5answers
112095 views

How to UPSERT (MERGE, INSERT ... ON DUPLICATE UPDATE) in PostgreSQL?

A very frequently asked question here is how to do an upsert, which is what MySQL calls INSERT ... ON DUPLICATE UPDATE and the standard supports as part of the MERGE operation. Given that PostgreSQL ...
462
votes
21answers
460537 views

Solutions for INSERT OR UPDATE on SQL Server

Assume a table structure of MyTable(KEY, datafield1, datafield2...). Often I want to either update an existing record, or insert a new record if it doesn't exist. Essentially: IF (key exists) run...
421
votes
16answers
223055 views

SQLite - UPSERT *not* INSERT or REPLACE

http://en.wikipedia.org/wiki/Upsert Insert Update stored proc on SQL Server Is there some clever way to do this in SQLite that I have not thought of? Basically I want to update three out of four co...
146
votes
2answers
53031 views

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

Is there an easy way to INSERT a row when it does not exist, or to UPDATE if it exists, using one MySQL query?
235
votes
12answers
318948 views

Oracle: how to UPSERT (update or insert into a table?)

The UPSERT operation either updates or inserts a row in a table, depending if the table already has a row that matches the data: if table t has a row exists that has key X: update t set mystuff.....
17
votes
3answers
4439 views

Is SELECT or INSERT in a function prone to race conditions?

I wrote a function to create posts for a simple blogging engine: CREATE FUNCTION CreatePost(VARCHAR, TEXT, VARCHAR[]) RETURNS INTEGER AS $$ DECLARE InsertedPostId INTEGER; TagName...
73
votes
4answers
61790 views

SQLite INSERT - ON DUPLICATE KEY UPDATE

MySQL has something like this: INSERT INTO visits (ip, hits) VALUES ('127.0.0.1', 1) ON DUPLICATE KEY UPDATE hits = hits + 1; As far as I'm know this feature doesn't exist in SQLite, what I want to...
5
votes
5answers
5804 views

Upserting in MS-access

I need to write an SQL query for MS-Access 2000 so that a row is updated if it exists, but inserted if it does not. (I believe this is called an "upsert") i.e. If row exists... UPDATE Table1 SET (....
40
votes
4answers
43112 views

How to Perform an UPSERT so that I can use both new and old values in update part

Stupid but simple example: Assume I have a table 'Item' where I keeps totals of the items that receive. Item_Name Items_In_Stock Item name is primary key here. How to i achieve the fol...

Previous Next