-1

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.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
user3770062
  • 153
  • 1
  • 1
  • 12

2 Answers2

1

You could use an update statement:

UPDATE my_table
SET    my_int_column = 0
WHERE  my_int_column IS NULL
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

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.

NurShomik
  • 237
  • 5
  • 14