How to make to overwrite the rows in PostgreSql?

Good day,

the query is executed through JDBC - INSERT INTO TableName( id, name) VALUES ('1', 'new_name');

A record with this key already exists, and there is duplicate key value violates unique constraint "TableName_pkey"
how to do a full overwrite of the entire record if a record with the same key already exists?

ON CONFLICT DO UPDATE - wants to specify which fields need updating.
Need to do a complete overwrite.
March 12th 20 at 07:56
2 answers
March 12th 20 at 07:58
I do not quite understand what you want to. Maybe you mean special. expression is excluded:
INSERT INTO TableName (id, name)
VALUES (1, 'Petya')

If you request a record with id=1 already existed, its name will be replaced by 'Peter'.
I mean if the record already exists, it should just reschedule for the new completely. - Wanda.Effertz commented on March 12th 20 at 08:01
March 12th 20 at 08:00
In Postgre there is no such mechanism.

If you have often this situation arises it is best to start with the update, because the upsert is a pretty expensive thing.

Find more questions by tags JDBCJavaPostgreSQL