How to preserve NULL values in PostgreSQL Datasource?

Hi, everyone,

I’m a system developer and I’m excited that I can use appsmith to create simple admin GUIs on databases for which I’ve previously used MS Access. After getting used to it, I find my way around quite well. Only for this point I could not find a solution.

My problem is NULL values ​​in a PostgreSQL datasource. When I display such a value in an input field in appsmith, it seems to be converted to an empty string or “0” (for Type Number) and written back to the database that way. Is there a way to preserve NULL values?

Many greetings

@Daniel Seems like we would need to support leaving null values as is instead of converting them into empty strings. However, wouldn’t doing a null check before updating work so that only non-empty values are written back to db? This could prevent overwriting null values with empty strings.

Hi @dancia,

for number fields its obvious to use the empty string to display or write the null value. For string/text fields I checked out how it works with MS-Access as frontend to PostgreSQL.

In all cases, a value is only updated in the database if it has been changed. Forth and back is not seen as a change.

If the text field is allowed to be NULL every empty string and every string containing one or more blanks is written as NULL to the database.

If the text field is defined NOT NULL, every empty string and every string containing one or more blanks is written as empty string to the database.

It’s not a solution to all data entry needs, but it works quite well.

@Daniel what you’re saying does make sense and is a smarter way for us to deal with data. We’ll definitely consider this improvement but what Dancia is suggesting for now is to simply add a null check from your end as {{ Input1.text === “” ? null : Input1.text }}

Thank you @Nikhil, that’s a good workaround. For a number field I had to put {{Table1.selectedRow.extid === null ? “” : Table1.selectedRow.extid}} in the Default Text to prevent conversion to “0”.