Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change a PG column to NULLABLE TRUE?

How can I accomplish this using Postgres? I've tried the code below but it doesn't work:

ALTER TABLE mytable ALTER COLUMN mycolumn BIGINT NULL;  
like image 832
mateusmaso Avatar asked Jan 27 '11 05:01

mateusmaso


People also ask

How do you change a column to nullable?

ALTER TABLE table_name ALTER COLUMN column_name DATA_TYPE [(COLUMN_SIZE)] NULL; In this syntax: First, specify the name of the table from which you want to change the column. Second, specify the column name with size which you want to change to allow NULL and then write NULL statement .

How do I change a column from null to NOT null in PostgreSQL?

2.6.3. To add a not-null constraint, which cannot be written as a table constraint, use this syntax: ALTER TABLE products ALTER COLUMN product_no SET NOT NULL; The constraint will be checked immediately, so the table data must satisfy the constraint before it can be added.

Are Postgres columns nullable by default?

NULL The column is allowed to contain null values. This is the default.

What is nullable in PostgreSQL?

The PostgreSQL NULL is the term used to represent a missing value. A NULL value in a table is a value in a field that appears to be blank. A field with a NULL value is a field with no value. It is very important to understand that a NULL value is different from a zero value or a field that contains spaces.


1 Answers

From the fine manual:

ALTER TABLE mytable ALTER COLUMN mycolumn DROP NOT NULL; 

There's no need to specify the type when you're just changing the nullability.

like image 69
mu is too short Avatar answered Oct 05 '22 11:10

mu is too short