I have issue with duplicate key

Highlighted
Six Stars

I have issue with duplicate key

This is my tmap:Capturetalend.PNG

The error message I have:

Batch entry 0 INSERT INTO "aggr". "Bench_tarifr_opecotarif" ("id", "cip13", "product", "libelle", "date_deb", "end date", "price") VALUES (0, '3400936315341', ' NICOTINELL 2MG MINT GUM S / S 96 ',' 1 to 31 January 2018 ', 20180101,20180131,10.9) was aborted: ERROR: the value of a duplicate key breaks the unique constraint "bench_tarifr_opecotarif_pkey"
   Detail: The key "(id) = (0)" already exists. Call getNextException to see other errors in the batch.
caused by: ERROR: The value of a duplicate key breaks the unique constraint "bench_tarifr_opecotarif_pkey"
   Detail: The key "(id) = (0)" already exists.

 

In the database I have a sequence for Id which is a primarykey.I already did truncate table.When I tried to insert ,I get the above error and no rows are inserted but when I do Insert/update,there is no error and just one line with Id 0 is inserted in the database table.I couldn't find the solution.If you need more details don't hesitate to contact me.


Accepted Solutions
Eleven Stars

Re: I have issue with duplicate key

Tmap sequence is different then db sequence.

Use the sequence in advance col. sequence name is mentioned in table definition.

Even then if it doesnot work , reset the db seq in database.
Regards
Abhishek KUMAR

View solution in original post


All Replies
Eleven Stars

Re: I have issue with duplicate key

1) is your ID column defined as serial? if this is the case you need not pass ID column while insert

if this doesnot work

2) if you need to provide ID value use advace setting , advance column . add you ID column detail here use nextval function to get next value of sequence.

 

let me know if it solve your issue

Regards
Abhishek KUMAR
Six Stars

Re: I have issue with duplicate key

The Id  column is not serial i guess.BDD.PNGBDDtable.PNG

The advance setting ,advance column does it means that using the sequence in the  tmap .If it is like that I have already used the sequence on the tmp(you can see the screen capture in the first post).

I tried without selecting the key in the tmap,the same errors still comes when doing insert.The BDD is empty.

I did insert update ,only one line is inserting ,where the line has id 0 and It doesn't take other lines.

I don't know why.

Is there some other solutions you can propose me?

Eleven Stars

Re: I have issue with duplicate key

Tmap sequence is different then db sequence.

Use the sequence in advance col. sequence name is mentioned in table definition.

Even then if it doesnot work , reset the db seq in database.
Regards
Abhishek KUMAR

View solution in original post

Six Stars

Re: I have issue with duplicate key

Thanks akumar!

I succeeded !The problem was the key.When I deleted the key on my target on the Talend,It worked.But its strange for me because I did another execution on another table by selecting the key ,It worked out,But here it didn't work.

So I understood that when the db is declared with the key and auto-increment sequence,I  should not aliment the key .

Thanks for your help!

 

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog