Linked Questions
131 questions linked to/from Insert, on duplicate update in PostgreSQL?
5 votes
1 answer
23k views
Make MERGE on PostgreSQL 9.5 [duplicate]
I'm trying to do a MERGE in PostgreSQL 9.5 and I get the following error: ERROR: syntax error at or near "MERGE" LINE 1: MERGE INTO TP_ESTADO_EQUIPOS AS EQ ^ ********** Error ********** ...
5 votes
1 answer
11k views
How to insert bulk rows and ignore duplicates in postgresql 9.3 [duplicate]
I have many rows of data to be inserted into a table. Table already has data in it. When I do a bulk insert like this, INSERT INTO permission(username, permission) values(('john','ticket_view'), ('...
1 vote
1 answer
10k views
Postgresql upsert query [duplicate]
Possible Duplicate: Insert, on duplicate update (postgresql) Cannot SELECT from UPDATE RETURNING clause in postgres Help to understand me syntax error. I try to make such implementation of ...
0 votes
1 answer
5k views
Postgres. Insert rows that do not exist and update rows that already exist in one SQL statement [duplicate]
I am trying to batch insert or update rows to a database in one postgres statement depending on whether the ID already exists in the table or not. I will be updating/inserting 100 or more rows at the ...
1 vote
1 answer
8k views
Why is this Postgres query throwing "duplicate key value violates unique constraint"? [duplicate]
I've implemented simple update/insert query like this: -- NOTE: :time is replaced in real code, ids are placed statically for example purposes -- set status_id=1 to existing rows, update others ...
2 votes
2 answers
5k views
Postgres 9.4.7 INSERT INTO without ON CONFLICT [duplicate]
I would really like to write a query like this: INSERT INTO test_table (id, dt, amt) VALUES(4, current_timestamp, 15) ON CONFLICT (id) DO UPDATE SET dt = VALUES(dt) amt = VALUES(amt) The ...
0 votes
3 answers
3k views
Upsert in node.js - what is `IF EXIST`? [duplicate]
Could someone explain the if exist command that is used in SQL? for example: if exist(select * from waiter){ update waiter set (...) where waiter_id='somevalue' } else{ insert into waiter ...
2 votes
1 answer
3k views
If exist return id else insert in postgres [duplicate]
I am new to postgres and i'm am having to populate a database using it. I cant submit my actual code for reference but my program is in java and i'm trying to do something along these lines. IF ...
1 vote
1 answer
3k views
Insert INTO where clause on postgresql [duplicate]
Possible Duplicate: Insert, on duplicate update (postgresql) Is this possible on PostgreSQL: insert record, if the record doesn't exists else update existing record Supposedly that the record ...
3 votes
1 answer
3k views
Isn't PostgreSQL single query execution atomic? [duplicate]
In my postgresql DB, I have a table "my_table" with primary key on columns (a, b). I wrote the query below for inserts into this table which ensures that the primary key constraint is never violated. ...
0 votes
1 answer
3k views
Update and Insert cases in postgresql function [duplicate]
I have a table tab with columns: userid, usercode, value I'm writing a plpgsql function that update/insert the table. In case userid & usercode exists I need to update value In case they don't I ...
2 votes
2 answers
982 views
using conditional logic : check if record exists; if it does, update it, if not, create it [duplicate]
I asked this last night, and got information on merging (which is unavailable in postgresql). I'm willing to try the workaround suggested But I'm just trying to understand why it can't be done with ...
0 votes
0 answers
2k views
support of merge query in postgresql [duplicate]
I want to create a merge query so that I can insert the new incoming record and update the record if there is any change in record. I created a query as: MERGE into sales AS TARGET USING sales1 AS ...
0 votes
1 answer
1k views
Is there an "Update if not exists insert" (like replace in MySQL)? [duplicate]
Is there an "update if not exists insert" function in Redshift, like replace in MySQL? If not, what should I do instead?
-1 votes
1 answer
479 views
Update postgresql if the key exist with php [duplicate]
Im converting my php app to work with postgresql instead of mysql. Before I had this function using PDO: $stmt = $db->prepare("INSERT INTO $table(id,name,info) VALUES(:id,:name,:info) ON ...