I have a postgreSQL table which accepts date in yyyy-mm-dd format and it is not accepting if the incoming date format is ''(no date). There could be some instances when '' gets passed as date. Could anyone help me write a function which checks if the incoming date is '' and then replaces it with NULL and then adds it to the db.
2 Answers
Use nullif()
insert into the_table (the_date_column)
values (nullif(?, ''))
Or for an update
update the_table
set the_date_column = nullif(?, '');
not null?update control_tracker set date='[regsub -all {\s} [string trim [regsub {\{.*} $whens1_12 ""]] "-" ]'