I am trying to replace empty cells in a column (type int) with an integer.
I am using Postgres. I have been able to replace them in a 'select' query using coalesce, but not sure how to alter the records permanently.
I am trying to replace empty cells in a column (type int) with an integer.
I am using Postgres. I have been able to replace them in a 'select' query using coalesce, but not sure how to alter the records permanently.
You could use an update
statement:
UPDATE my_table
SET my_int_column = 0
WHERE my_int_column IS NULL
This does not answer your question. However, this does the opposite. So, in case someone is looking up for replacing a value with NULL
in select
query result and reached this post, use the nullif
function:
select last_name||', '||first_name as "Name", nullif(salary, 0) as "Salary" from employee;
Here, it will return all records including records where salary is zero, but will show empty cells in place of zero.