I have a REST API written in Spring that inserts data into a PostgreSQL database. I would like to avoid empty strings in the database -- and let empty fields be null instead.
Is there anything meaningful I can do in the database side?
For instance, I tried this and while the syntax works from the console, it won't work with named parameters when used by JdbcTemplate in Spring.
insert
...
nullif(trim(:value), '')
Or perhaps I should just clean the data programmatically?
Edit: To clarify, I am asking about the concepts, not about the specific way of achieving the goal provided as an example, or the resulting error message.