Unix Technical Forum

BUG #3542: Dropped and recreated columns have problems with NOT NULL contraints

This is a discussion on BUG #3542: Dropped and recreated columns have problems with NOT NULL contraints within the pgsql Bugs forums, part of the PostgreSQL category; --> The following bug has been logged online: Bug reference: 3542 Logged by: Jens Schicke Email address: j.schicke@asco.de PostgreSQL version: ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Bugs

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 11:02 AM
Jens Schicke
 
Posts: n/a
Default BUG #3542: Dropped and recreated columns have problems with NOT NULL contraints


The following bug has been logged online:

Bug reference: 3542
Logged by: Jens Schicke
Email address: j.schicke@asco.de
PostgreSQL version: 8.2.4
Operating system: GNU/Linux
Description: Dropped and recreated columns have problems with NOT
NULL contraints
Details:

pizza_de=# alter table store_flags add column flag integer;
ALTER TABLE
pizza_de=# alter table store_flags drop column flag;
ALTER TABLE
pizza_de=# alter table store_flags add column flag integer not null;
ERROR: column "flag" contains null values
pizza_de=# alter table store_flags drop column flag;
ERROR: column "flag" of relation "store_flags" does not exist
pizza_de=# alter table store_flags add column flag integer not null;
ERROR: column "flag" contains null values

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 11:02 AM
Heikki Linnakangas
 
Posts: n/a
Default Re: BUG #3542: Dropped and recreated columns have problemswith NOT NULL contraints

What did you expect?

Jens Schicke wrote:
> pizza_de=# alter table store_flags add column flag integer;
> ALTER TABLE
> pizza_de=# alter table store_flags drop column flag;
> ALTER TABLE
> pizza_de=# alter table store_flags add column flag integer not null;
> ERROR: column "flag" contains null values


The column was not added. It would've been filled with NULLs, which
would violate the NOT NULL constraint. You have to give a DEFAULT if you
add a column with a NOT NULL constraint.

> pizza_de=# alter table store_flags drop column flag;
> ERROR: column "flag" of relation "store_flags" does not exist


The column doesn't exist, because the add column above failed, and was
rolled back.

> pizza_de=# alter table store_flags add column flag integer not null;
> ERROR: column "flag" contains null values


Same as above..

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 11:02 AM
Stephan Szabo
 
Posts: n/a
Default Re: BUG #3542: Dropped and recreated columns have problemswith NOT NULL contraints


On Thu, 16 Aug 2007, Jens Schicke wrote:

> The following bug has been logged online:
>
> Bug reference: 3542
> Logged by: Jens Schicke
> Email address: j.schicke@asco.de
> PostgreSQL version: 8.2.4
> Operating system: GNU/Linux
> Description: Dropped and recreated columns have problems with NOT
> NULL contraints
> Details:
>
> pizza_de=# alter table store_flags add column flag integer;
> ALTER TABLE
> pizza_de=# alter table store_flags drop column flag;
> ALTER TABLE
> pizza_de=# alter table store_flags add column flag integer not null;
> ERROR: column "flag" contains null values


Yes, because the default is null which means that any existing rows in the
table would violate the constraint as soon as the new column is added with
default values. You need to specify the default at the same time, or if
you don't wish to or cannot do that, make the column, fill it with
non-null values, and then add the not null condition.

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:40 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com