Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating integer column with null values in postgres

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"

like image 482
no_name Avatar asked Oct 18 '17 04:10

no_name


People also ask

Can we insert null in integer column in PostgreSQL?

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 .

How do you UPDATE a column WHERE value 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.

How do you handle null values in PostgreSQL?

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 “=” “!=

How do you UPDATE columns in PostgreSQL?

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.


1 Answers

This should be,

UPDATE table1 
SET column_a = NULL
WHERE column_b = 'XXX';
like image 160
shiv Avatar answered Oct 16 '22 10:10

shiv