I would like to update my column with other column in other table. Before doing so, I would like to nullify my column(integer) first. However, below code did not work. (column_a: bigint; column_b: text)
UPDATE table1
SET column_a IS NULL
WHERE column_b = 'XXX';
ERROR: syntax error at or near "ISNULL"
An integer column can be null, but '' is an empty string not null. The right syntax for a null integer (or any other sql type) is null .
UPDATE [table] SET [column]=0 WHERE [column] IS NULL; Null Values can be replaced in SQL by using UPDATE, SET, and WHERE to search a column in a table for nulls and replace them.
In PostgreSQL, NULL means no value. In other words, the NULL column does not have any value. It does not equal 0, empty string, or spaces. The NULL value cannot be tested using any equality operator like “=” “!=
First, specify the name of the table that you want to update data after the UPDATE keyword. Second, specify columns and their new values after SET keyword. The columns that do not appear in the SET clause retain their original values. Third, determine which rows to update in the condition of the WHERE clause.
This should be,
UPDATE table1
SET column_a = NULL
WHERE column_b = 'XXX';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With