forcedotcom / phoenix

BSD 3-Clause "New" or "Revised" License
558 stars 227 forks source link

Column should not be added/altered with NOT NULL constraint in a table where some records already present #532

Closed pankaj2461 closed 10 years ago

pankaj2461 commented 11 years ago

ALTER TABLE should not add/modify a column with NOT NULL constraint in table where some records are already present.

Currently the same is allowed in phoenix 2.0.1 release, which is causing inconsistent behavior while querying on the added column with "IS NULL" or "IS NOT NULL" utilities

samarthjain commented 11 years ago

Pankaj,

Did you mean adding a new NOT NULL column which is part of a row key? If yes, then we already don't allow adding non null columns that will be part of PK.

CREATE TABLE test_table (a_string varchar not null, col1 integer, cf1.col2 integer CONSTRAINT pk PRIMARY KEY (a_string))

ALTER TABLE test_table ADD b_string VARCHAR NOT NULL PRIMARY KEY

Fails with the error: Error: ERROR 1006 (42J04): Only nullable columns may be added to a multi-part row key. columnName=B_STRING SQLState: 42J04 ErrorCode: 1006

However, we do currently allow adding a non null column to the table if it is not part of the PK. I am working on addressing that issue.

pankaj2461 commented 11 years ago

Thanks Samarth for replying..!!

I meant for adding a NOT NULL column to the table (few records already present) if it is not part of the PK.

We should not allow to add a NOT NULL column when records present in the table.

jtaylor-sfdc commented 10 years ago

Fixed in master by @samarthjain. Thanks for the contribution!