Skip to content
Advertisement

Insert data into Postgresql with duplicate values

I need to insert dataset in postgresql.

the problem is that there are many duplicate values in the request. As the result database should involve

Or nothing if this dataset is in database. How should I make my query?

P.S.

The table is:

Advertisement

Answer

If you don’t want duplicates inserted, then add a unique index or constraint:

If you want your insert to succeed for the non-duplicated values, then add:

as the last line of the INSERT.

Here is a db<>fiddle.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement