Setting date value as null on editable table

I have a table where one of the columns is of date format, and the data comes from a 'SELECT * FROM table_name' type of query (postgres db).

I allow editing on the table. The user can change the date of a record, and remove the date from a record that already has one. The problem is when the user removes the date from a record, the new (empty) date gets added to the changeset as an empty string "".

Why is that a problem? When the user changes the table, I allow saving the changes to the database, using a save action add-on.

I have defined a bulkinsert query to update the affected rows on the db table, where the "Array of records to update" is:

{{
  invoicePositionsTable.changesetArray
}}

Postgres rejects this update because an empty string "" is not a valid value for dates.

Is there a way to change my table so that when the user removes a date, the default value is null?

Thanks

Hey @Javi_V,

You can use something like this:

{{
  invoicePositionsTable.changesetArray.map(item => {
    if (item.start_date === "") {
      item.start_date = null;
    }
    return item;
  })
}}

just make sure to change the key of your date.