Connecting Tech Pros Worldwide Forums | Help | Site Map

Add not null column in a table

Newbie
 
Join Date: Aug 2007
Location: Germay
Posts: 10
#1: Sep 13 '07
Hi again

I have another question, I would like to add NOT NULL column in my table. I have done like this :

ALTER TABLE patent ALTER COLUMN patent_pri_date SET NOT NULL;

but it doesn't work and give the following error :
ERROR: ALTER TABLE: Attribute "patent_pri_date" contains NULL values

is any body can help me how can i add NOT NULL column to my table ?, I use postgresql 7.4. Thank you very much.

Best regards,
Bogie

Moderator
 
Join Date: Dec 2006
Location: Europe
Posts: 293
#2: Sep 13 '07

re: Add not null column in a table


Quote:

Originally Posted by bogie

Hi again

I have another question, I would like to add NOT NULL column in my table. I have done like this :

ALTER TABLE patent ALTER COLUMN patent_pri_date SET NOT NULL;

but it doesn't work and give the following error :
ERROR: ALTER TABLE: Attribute "patent_pri_date" contains NULL values

is any body can help me how can i add NOT NULL column to my table ?, I use postgresql 7.4. Thank you very much.

Best regards,
Bogie


I looks like there are rows in which pri_date column contans NULLS values. U should fill it first.
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#3: Sep 13 '07

re: Add not null column in a table


Quote:

Originally Posted by bogie

Hi again

I have another question, I would like to add NOT NULL column in my table. I have done like this :

ALTER TABLE patent ALTER COLUMN patent_pri_date SET NOT NULL;

but it doesn't work and give the following error :
ERROR: ALTER TABLE: Attribute "patent_pri_date" contains NULL values

is any body can help me how can i add NOT NULL column to my table ?, I use postgresql 7.4. Thank you very much.

Best regards,
Bogie

You can add NOT NULL columns to a table only if the table is EMPTY and does not contain any ROW.
Moderator
 
Join Date: Dec 2006
Location: Europe
Posts: 293
#4: Sep 13 '07

re: Add not null column in a table


Quote:

Originally Posted by amitpatel66

You can add NOT NULL columns to a table only if the table is EMPTY and does not contain any ROW.

I in version 8.* u can add not null on a column if it does not contain null values. Maybe I'm wrong but in earlier versions it's looks the same.
Newbie
 
Join Date: Sep 2007
Posts: 15
#5: Sep 14 '07

re: Add not null column in a table


attention......
attention......
attention......
attention......
attention......
amitpatel66's Avatar
Moderator
 
Join Date: Mar 2007
Location: Hyderabad, India
Posts: 2,192
#6: Sep 14 '07

re: Add not null column in a table


Quote:

Originally Posted by rski

I in version 8.* u can add not null on a column if it does not contain null values. Maybe I'm wrong but in earlier versions it's looks the same.

Yes It is possible to make the COLUMN NOT NULL in case if it does not contain any NULL value
Newbie
 
Join Date: Aug 2007
Location: Germay
Posts: 10
#7: Sep 18 '07

re: Add not null column in a table


Quote:

Originally Posted by rski

I looks like there are rows in which pri_date column contans NULLS values. U should fill it first.


Hi

Thank you very much for the advice, it works.

Best regards,
Bogie
Reply