how to get a primary key from a csv file to a database

how to get a primary key from a csv file to a database

Hello
I would like to insert from my csv file the primary key into the table of my database but not in primary key in the table.
I need to use a tMap and i tried to make a condition (!String.valueOf(table.value1).equals(String.valueOf(csv.valueOf))) to insert in database.
The problem is that if there is nothing in database, every line go to the table even if there is several time the same value. And if there is something in the table of the database that works....So when i run my job, it works only one time on two....
I am trying to process like the foreign key. i use the same condition in my tMap. In my job, i have in row main my tFileInput (csv file), in lookup row a tPostgresqlInput connected to my tMap which is connected to a tpostgresqlOutput.
So I am trying to do the same but my problem is that in the tPostgresqlinput and the tPostgresqlOutput i have the same table...
So i was trying to think about inserting one line at a time but i don't know if it's possible...
Could you help me.....
I am in a hurry
thanks
tomlaurent
One Star

Re: how to get a primary key from a csv file to a database

Hello,
I don't understand very well what your problem is.
Do you have a column in your csv file will become primary key, like (assuming A1 is your primary key :
CSV :
A1 B1 C1
1 xy zz
1 ed ee
2 de ee
3 dd fe
2 xz fr
and you want :
Table :
A1 B1 C1
1 xy zz
2 de ee
3 dd fe
Can you post what input and output you want to obtain? And maybe some screenshots of your current job.
Thank you,
Chris

Re: how to get a primary key from a csv file to a database

Hello Chris,
Yes in my csv file i have a primary key on the fisrt column, like A1 in your example
A1 B1 C1
1 xy zz
1 ed ee
2 de ee
3 dd fe
2 xz fr
I read that i can use a tUniqrow to take off the double value, but my problem is that i would like to use a tMap.
In my line of the csv file, i need to get all the errors (for example the primary key, length() of string, etc....) and if i use a tUniqRow that take of the line directly and i don't know if there is others errors on the line.
I was thinking is there an expresion like, String.valueOf(row.value1).equals(something) to know if the value is Unique or not?
I tried to use the method isUnique() but that didn't work.
thanks
tomlaurent
One Star

Re: how to get a primary key from a csv file to a database

Hello,
I think I understand your problem. Each row can have multiple errors that you want to log, and then after that you want to take off duplicate primary keys and only insert one row for each primary key (I guess you will insert the one that doesn't have any errors).
How do you want to log these errors? Do you want to process bad lines or simply output the number of errors? Can you give the nature of your outputs and above all what your resulting table would be like.
Thanks.
Chris