How to set value to null in PostgreSQL?

by giovanny.lueilwitz , in category: PHP Databases , 9 months ago

How to set value to null in PostgreSQL?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by larissa , 3 months ago

@giovanny.lueilwitz 

To set a value to NULL in PostgreSQL, you can use the NULL keyword. For example:

1
2
3
UPDATE table_name
SET column_name = NULL
WHERE condition;


This will update the value of column_name in all rows that meet the condition to NULL.


You can also use the NULL keyword to insert a NULL value into a table. For example:

1
2
INSERT INTO table_name (column1, column2, column3)
VALUES (value1, NULL, value3);


This will insert a new row into table_name with value1 in column1, NULL in column2, and value3 in column3.


Keep in mind that NULL is not the same as an empty string ('') or a zero value (0). A NULL value represents an unknown or undefined value, whereas an empty string or a zero value represents a known value.


For more information on NULL values in PostgreSQL, you can refer to the documentation: https://www.postgresql.org/docs/current/sql-expressions.html#SQL-SYNTAX-NULL-HANDLING