Issue Details (XML | Word | Printable)

Key: DERBY-396
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Bryan Pendleton
Reporter: Kumar Matcha
Votes: 14
Watchers: 8
Operations

If you were logged in you would be able to see more operations.
Derby

Support for ALTER STATEMENT to DROP , MODIFY, RENAME a COLUMN

Created: 28/Jun/05 09:12 PM   Updated: 01/Jul/09 12:34 AM
Return to search
Component/s: SQL
Affects Version/s: None
Fix Version/s: 10.3.1.4

Time Tracking:
Not Specified

File Attachments:
  Size
File Licensed for inclusion in ASF works dropColumn_1.diff 2006-07-05 08:11 AM Bryan Pendleton 16 kB
Environment: LINUX
Issue Links:
Cloners
 
Reference

Resolution Date: 17/Nov/06 10:32 PM


 Description  « Hide
Alter Statement should support dropping a column, modifying a column to a different data type , rename a column.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Rick Hillegas added a comment - 05/Aug/05 08:24 AM
---------------------------------

ANSI supplies syntax for dropping a column:

  ALTER TABLE tableName DROP columnName

----------------------------------------------

Derby already supports some datatype modification. It would be interesting to understand the use cases for additional datatype mods.

----------------------------------------------

I can't find ANSI syntax for renaming a column nor can I find this feature in DB2. Oracle and Postgres agree on the following syntax:

  ALTER TABLE tableName RENAME COLUMN oldColumnName TO newColumnName

MySQL supports the following less intuitive syntax:

  ALTER TABLE tableName CHANGE oldColumnName newColumnName oldDatatype

Is the Oracle/Postgres agreement a good enough standard?

Rick Hillegas made changes - 06/Aug/05 12:01 AM
Field Original Value New Value
Comment [ ANSI supplies syntax for dropping columns:

  ALTER TABLE tableName DROP COLUMN columnName

--------------------------


Derby already supports some changes to datatypes. It would be interesting to understand what other modifications are needed and what their use cases are.

--------------------------

I can't find ANSI syntax for renaming a column. I also can't find this feature in DB2. Oracle and Postgres agree on the following syntax:

  ALTER TABLE tableName RENAME COLUMN oldColumnName TO newColumnName

MySQL supports less intuitive syntax:

  ALTER TABLE tableName CHANGE oldColumnName newColumnName oldDatatype

Is the Oracle/Postgres agreement a good enough standard for us? ]
Rick Hillegas made changes - 06/Aug/05 12:03 AM
Comment [ Dropping a column seems well defined. The ANSI syntax is:

  ALTER TABLE tableName DROP COLUMN columnName

------------------------------

It would be interesting to understand the use cases for datatype modification.

------------------------------

I can't find ANSI syntax for renaming columns. I also can't find this feature in the DB2 reference manual. Oracle and Postgres support the following reasonable syntax:

  ALTER TABLE tableName RENAME COLUMN oldColumnName TO newColumnName

MySQL supports the same functionality with less intuitive syntax:

  ALTER TABLE tableName CHANGE oldColumnName newColumnName oldColumnDatatype

Is the Oracle/Postgres agreement good enough for us to declare a standard here?
]
Kumar Matcha added a comment - 17/Aug/05 02:46 PM
Derby is supposed to be SQL-92E compliance and supports key features in the SQL-99 standards. If you take a look at the SQL92 Standard for ALTER TABLE STATEMENT :

<alter table statement> ::=
              ALTER TABLE <table name> <alter table action>

         <alter table action> ::=
                <add column definition>
              | <alter column definition>
              | <drop column definition>
              | <add table constraint definition>
              | <drop table constraint definition>

So its supposed to provide support for dropping a column. Although RENAME COLUMN is vendor specific, Oracle/Postgres aggrement is a good enough standard.


Rick Hillegas made changes - 17/Oct/05 10:37 PM
Link This issue relates to DERBY-168 [ DERBY-168 ]
Rick Hillegas made changes - 17/Oct/05 10:38 PM
Link This issue relates to DERBY-119 [ DERBY-119 ]
Rick Hillegas made changes - 17/Oct/05 10:39 PM
Link This issue relates to DERBY-165 [ DERBY-165 ]
Scott MacDonald made changes - 28/Oct/05 02:57 AM
Assignee Scott MacDonald [ scottmmd ]
Andrew McIntyre made changes - 28/Oct/05 04:09 AM
Priority Blocker [ 1 ] Critical [ 2 ]
Scott MacDonald added a comment - 09/Nov/05 04:57 AM
I am presently working on the Rename and Drop column issues.

As discussed previously on this Comment page, should the Oracle and Postgres syntax for renaming and dropping columns be followed?

The syntax is:

ALTER TABLE <table_name> DROP COLUMN <table_name>

ALTER TABLE <table_name> RENAME COLUMN <old_name> TO <new_name>


I have also been browsing documentation for Oracle, Postgres, and DB2 and doing some simple testing in DB2 regarding contstraints on renaming and dropping columns.

I have found that any column can be dropped, so long as it does not affect the referential integrity of the table or any other tables in the database (ie. as long as the column is not a primary or foreign key).

I have also found that any column can be renamed so long as the new column name is not already the name of another column in the table. The new column name must also be either an ordinary or delimited identifier.

If anybody has any comments on these topics before I begin implementation, I would like to hear them.

Thanks,
Scott

Satheesh Bandaram added a comment - 09/Nov/05 05:29 AM
SQL standard specifies DROP COLUMN syntax as:

ALTER TABLE <table name> DROP [COLUMN ]<column name><drop behavior>

<drop behavior>::= CASCADE | RESTRICT

You have to define if you are implementing CASCADE or RESTRICT behavior. Restrict would be easier to implement.

About RENAME COLUMN, it is not defined in the SQL standard. Derby typically allows SQL conforming syntax, so not sure about this one...

Rick Hillegas added a comment - 09/Nov/05 06:48 AM
I think that the Oracle/Postgres RENAME syntax is straightforward and good enough. Its similarity to Derby's RENAME TABLE syntax is also inviting. MySQL's syntax is, frankly, odd. ANSI and DB2 are silent on the issue. So I say, go with the inviting, straightforward syntax already embraced by two big players.

Rick Hillegas added a comment - 23/Nov/05 11:27 PM
Enhancement request 396 tracks various ALTER TABLE improvements, including column-dropping.

Rick Hillegas made changes - 23/Nov/05 11:27 PM
Link This issue is cloned as DERBY-726 [ DERBY-726 ]
Neil Weber added a comment - 28/Dec/05 07:00 PM
What's also odd is that the DatabaseMetaData for Derby returns true for supportsAlterTableWithDropColumn(). Since Derby doesn't support dropping columns, the meta data should be false.

Rick Hillegas added a comment - 28/Feb/06 01:09 AM
Downgrading priority to major.

Rick Hillegas made changes - 28/Feb/06 01:09 AM
Priority Critical [ 2 ] Major [ 3 ]
Rick Hillegas made changes - 28/Feb/06 06:53 AM
Assignee Scott MacDonald [ scottmmd ]
Dheeraj Dhiman added a comment - 13/Apr/06 06:03 PM
Hello Scott MacDonald !!
I m dheeraj !
I m switch from sql server to apache derby for my project !!
You say We can rename or drop a column from table !!
But i just try this & exception occur !!
My case is ::
I just create a table .

create table simple( name varchar(100), rollno bigint , fullName varchar(100));
table create after excuting this statement .

but now i want to change name of column rollno !!

I try ur suggetion which is given by you !!

you say ::

alter table simple rename column rollno to serialno ;
After excuting this query error occur ;
ERROR 42X01: Syntax error: Encountered "RENAME" at line 1, column 17.

&& i m also try another thing if we want drop a column !!
alter table simple drop column name ;
ERROR 42X01: Syntax error: Encountered "drop" at line 1, column 17


SWo now how can i drop or rename a column in apache derby !!
The table simple table have no primary key & no other forignkey !!
so how can i do this !!
I have mail accoutn on your apache derby jira log .
with name dheeraj.dhiman
or you can mail me at my email id
dheeraj.dhiman@gmail.com

I wanna answer of this problem as early as possible !!
Thanks !!




Wade Chandler added a comment - 17/Jun/06 03:17 AM
Hmmm. I think what Scott said was he is working on it and no where did I see where he said it works. He mentions something working in another server. Did you see him write something else some where besides this issue?

Rick Hillegas added a comment - 17/Jun/06 06:15 AM
Hi Wade,

Scott did not submit a patch for this issue and he has moved on to other pursuits. This issue is currently unassigned.

Bryan Pendleton added a comment - 04/Jul/06 06:16 AM
I am interested in working on this issue, and would like to hear from others who are interested in it.

I propose to start by working on ALTER TABLE DROP [COLUMN] column [CASCADE|RESTRICT].

If that goes well, I'll move on to some of the other ALTER TABLE column variants.

Following the suggestion made by Dan on the mailing list
(http://www.nabble.com/forum/ViewPost.jtp?post=1252308), I'm hoping to wire up the
parser to the existing Alter Table support code.

I've got a prototype implementation of the DROP COLUMN support working, and
will be asking the list for some help with parser issues soon.

Bryan Pendleton made changes - 04/Jul/06 06:16 AM
Assignee Bryan Pendleton [ bryanpendleton ]
Bryan Pendleton added a comment - 05/Jul/06 08:11 AM
Attached file 'dropColumn_1.diff' is a first attempt at providing support for
   ALTER TABLE DROP COLUMN

This patch contains some small changes to the parser/compiler to recognize
the new ALTER TABLE syntax, and uses the existing code in
AlterTableConstantAction.java for the execution support.

The patch contains a small amount of new test code, but really I haven't done
much testing yet; I suspect that there is a LOT more testing to do, and I'm
hoping that reviewers will suggest particular test cases that would be of
interest.

I'm particularly interested in feedback about the parser changes, and about testing,
but of course all feedback is very gratefully appreciated.

Bryan Pendleton made changes - 05/Jul/06 08:11 AM
Attachment dropColumn_1.diff [ 12336346 ]
Bryan Pendleton added a comment - 08/Jul/06 11:10 PM
I propose to file separate JIRA issues for the topics described here:

1) drop column
2) rename column
3) change column from null to not null, or vice versa
4) change column default value
5) change column datatype

DERBY-119 already exists to track issue (3); I will be filing 4 new issues, linked to this one, to track the other topics. DERBY-168 was previously filed for issue (4), but was closed by changing the documentation, so I will open a new issue to track addition of the functionality.

Bryan Pendleton made changes - 08/Jul/06 11:17 PM
Link This issue is related to DERBY-1489 [ DERBY-1489 ]
Bryan Pendleton made changes - 08/Jul/06 11:24 PM
Link This issue is related to DERBY-1490 [ DERBY-1490 ]
Bryan Pendleton made changes - 08/Jul/06 11:24 PM
Link This issue relates to DERBY-1490 [ DERBY-1490 ]
Bryan Pendleton made changes - 08/Jul/06 11:26 PM
Link This issue is related to DERBY-1491 [ DERBY-1491 ]
Bryan Pendleton made changes - 08/Jul/06 11:26 PM
Link This issue relates to DERBY-1491 [ DERBY-1491 ]
Bryan Pendleton made changes - 09/Jul/06 01:40 AM
Link This issue is related to DERBY-1492 [ DERBY-1492 ]
Bryan Pendleton made changes - 09/Jul/06 01:40 AM
Link This issue relates to DERBY-1492 [ DERBY-1492 ]
Bryan Pendleton made changes - 16/Jul/06 04:27 PM
Link This issue is related to DERBY-1515 [ DERBY-1515 ]
Bryan Pendleton made changes - 16/Jul/06 04:27 PM
Link This issue relates to DERBY-1515 [ DERBY-1515 ]
Bryan Pendleton added a comment - 16/Jul/06 04:29 PM
I got confused and opened DERBY-1492 accidentally; it was a duplicate of DERBY-119 so I closed it. Then I opened DERBY-1515 to track changing a column's datatype.

Bryan Pendleton added a comment - 16/Jul/06 05:27 PM
I believe this issue can now be closed, and the other issues tracked independently. If you disagree, please comment accordingly.

Kathey Marsden added a comment - 16/Jul/06 06:53 PM
Since this issue has 14 votes, I think I would prefer to see it left open and the other issues linked as "part of" this one. That way the vote information can be preserved until the complete issue is resolved.


Bryan Pendleton added a comment - 10/Sep/06 08:02 PM
DERBY-119 and DERBY-1491 have made it into the 10.2 release, yay!
DERBY-1489 has made good progress, but is currently blocked on some
interactions with the new GRANT/REVOKE feature. No significant progress
on DERBY-1490 or DERBY-1515 has occurred recently.

Bryan Pendleton added a comment - 09/Nov/06 12:45 AM
I propose to mark this issue resolved for 10.3.

Can anybody see any part of this feature which has not yet been addressed?

Kathey, I know you were concerned that we not prematurely close this issue. How
do you feel about marking it as resolved at this point?

Rajesh Kartha added a comment - 09/Nov/06 01:59 AM
I tend to agree with Bryan. As I understand ,the only issue that remains is to ALTER a COLUMN's DATATYPE, and the work-around provided in DERBY-1515 seems reasonable enough.

-Rajesh

Andrew McIntyre made changes - 14/Nov/06 07:09 AM
Link This issue is related to DERBY-1909 [ DERBY-1909 ]
Bryan Pendleton added a comment - 17/Nov/06 10:32 PM
Thanks Rajesh! I've marked this issue as FIXED in 10.3. If the community feels that there are additional needs in the area of table alteration, please either re-open this issue with information about what is needed, or (probably simpler) open a new issue describing the remaining needs.

Bryan Pendleton made changes - 17/Nov/06 10:32 PM
Resolution Fixed [ 1 ]
Fix Version/s 10.3.0.0 [ 12310800 ]
Status Open [ 1 ] Resolved [ 5 ]
Andrew McIntyre added a comment - 13/Dec/07 09:04 AM
This issue has been resolved for over a year with no further movement. Closing.

Andrew McIntyre made changes - 13/Dec/07 09:04 AM
Status Resolved [ 5 ] Closed [ 6 ]
Dag H. Wanvik made changes - 01/Jul/09 12:34 AM
Issue Type New Feature [ 2 ] Improvement [ 4 ]