Four Stars

Writing null values into database instead of empty strings

Hi,

 

I try inserting data from a csv file into a postgres database. In the csv file several cells are empty. In my schema the columns are all nullable.

Nevertheless, talend writes empty strings '' into the database instead of null values.

Do you have any idea how I can insert null values?

 

Thanks

Hein

 

Schema.JPG

 

Screenshot.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
Six Stars

Re: Writing null values into database instead of empty strings

Hi,

Please try adding one more component tmap in between both the connectors and for that column alone check for empty string if so then set null, something like
Row1. Field==''? null:row1.field.

Let me know if above works.
Thanks,
Ram
5 REPLIES
Six Stars

Re: Writing null values into database instead of empty strings

Hi,

Please try adding one more component tmap in between both the connectors and for that column alone check for empty string if so then set null, something like
Row1. Field==''? null:row1.field.

Let me know if above works.
Thanks,
Ram
Ten Stars

Re: Writing null values into database instead of empty strings

Don't use == to compare Strings. Use .equals() or in this case .isempty() instead.
Four Stars

Re: Writing null values into database instead of empty strings

Thank you for your quick answers.

I had hoped there was a checkbox or something I missed.

 

But your solution will definitely work.

Five Stars

Re:how to replace null value by '.'

hello ,

i have one column for monile number and some user not inserted value in that column ..

 

so i wand to replace that value by dot '.'

 

 

 

Thank you

Six Stars

Re: Writing null values into database instead of empty strings

If you are using the suscription version, you can leverage Dynamic schema and do something like that:

 

JobOverview.PNGJob OverviewFlatFile.PNGFile extractDynamic.PNGFile SchemaSchema_DYN.PNGExtract Dynamic SchematLog.PNGtLog

 

The code in the tJavaRow is

 

Dynamic columns = input_row.dyn; //extract Dynamic
 
//looping on each columns of the row for (int i = 0; i < columns.getColumnCount(); i++) { DynamicMetadata columnMetadata = columns.getColumnMetadata(i); //extracting metadata
//if empty then replace by null if(columnMetadata.getType().equals("id_String") && ((String)columns.getColumnValue(i)).isEmpty()) { columns.setColumnValue(i, null); } }
//replacing the stream row by the new updated one output_row.dyn = columns;