dbTalk Databases Forums  

RE: [Info-ingres] Ingres 3.0.2, alter table... alter column..., strange results

comp.databases.ingres comp.databases.ingres


Discuss RE: [Info-ingres] Ingres 3.0.2, alter table... alter column..., strange results in the comp.databases.ingres forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Paul White
 
Posts: n/a

Default RE: [Info-ingres] Ingres 3.0.2, alter table... alter column..., strange results - 09-06-2005 , 09:39 AM






Quote:
(What do you do with the column values for all the rows that
existed before you added the column? Those rows all have defaults
for the new column. Ingres doesn't want to go back and rewrite all
the rows with the new default value, and it doesn't know which rows
to rewrite anyway.)
I'd like to think I can set a default value to apply only to records inserted from this point on. If I wanted to modify old records which are already in the table I would do an explicit update. I'd be pretty cranky if the dbms changed my null values to some other value.

Paul
ps. MSSQL doesnt support it either.



Reply With Quote
  #2  
Old   
Gerhard Hofmann
 
Posts: n/a

Default Re: [Info-ingres] Ingres 3.0.2, alter table... alter column..., strangeresults - 09-06-2005 , 11:11 AM






Paul White wrote:
Quote:
(What do you do with the column values for all the rows that
existed before you added the column? Those rows all have defaults
for the new column. Ingres doesn't want to go back and rewrite all
the rows with the new default value, and it doesn't know which rows
to rewrite anyway.)


I'd like to think I can set a default value to apply only to records inserted from this point on. If I wanted to modify old records which are already in the table I would do an explicit update. I'd be pretty cranky if the dbms changed my null values to some other value.

Paul
ps. MSSQL doesnt support it either.

My assumption was the same: a default value should only affect new rows
but not existing ones.

Regards
Gerhard


Reply With Quote
  #3  
Old   
Betty & Karl Schendel
 
Posts: n/a

Default Re: [Info-ingres] Ingres 3.0.2, alter table... alter column...,strange results - 09-06-2005 , 11:35 AM



At 6:11 PM +0200 9/6/05, Gerhard Hofmann wrote:
Quote:
Paul White wrote:
(What do you do with the column values for all the rows that
existed before you added the column? Those rows all have defaults
for the new column. Ingres doesn't want to go back and rewrite all
the rows with the new default value, and it doesn't know which rows
to rewrite anyway.)


I'd like to think I can set a default value to apply only to
records inserted from this point on. If I wanted to modify old
records which are already in the table I would do an explicit
update. I'd be pretty cranky if the dbms changed my null values to
some other value.

Paul
ps. MSSQL doesnt support it either.

My assumption was the same: a default value should only affect new
rows but not existing ones.
While I do have a certain amount of sympathy for this position, I don't
think it's wise to rush into it. The meaning of a relation shouldn't be
time sensitive. To say that some rows have an x column default of V1,
while others have a default for the same column of V2 just because they
happened to be inserted later, rubs me the wrong way. And it still leaves
relatively unanswered the question of just what values does column X
have in pre-existing rows, anyway, if X was added or altered after table
creation? The DBMS is not (currently) in a position to instantiate
anything other than zero-blank-or-null for a column when retrieving a
row that doesn't currently contain that column (because it's an old row).

I wouldn't be fanatically against allowing value defaults for add column
or alter column, but I'd want to see some sort of coherent statement of
semantics that preserves the meaning of pre-existing rows.

Karl


Reply With Quote
  #4  
Old   
Gerhard Hofmann
 
Posts: n/a

Default Re: [Info-ingres] Ingres 3.0.2, alter table... alter column...,strange results - 09-07-2005 , 07:50 AM



Betty & Karl Schendel wrote:
Quote:
Gerhard wrote:
My assumption was the same: a default value should only affect new
rows but not existing ones.


While I do have a certain amount of sympathy for this position, I don't
think it's wise to rush into it. The meaning of a relation shouldn't be
time sensitive. To say that some rows have an x column default of V1,
while others have a default for the same column of V2 just because they
happened to be inserted later, rubs me the wrong way. And it still leaves
relatively unanswered the question of just what values does column X
have in pre-existing rows, anyway, if X was added or altered after table
creation? The DBMS is not (currently) in a position to instantiate
anything other than zero-blank-or-null for a column when retrieving a
row that doesn't currently contain that column (because it's an old row).

I wouldn't be fanatically against allowing value defaults for add column
or alter column, but I'd want to see some sort of coherent statement of
semantics that preserves the meaning of pre-existing rows.
I am the original poster of this thread, maybe I should have described
my problem in detail.

We have a Java / JDBC based application that should - in a case of
software updates - perform all necessary table structure changes so that
software version and table structures will always match.

In some cases it will be necessary to add a column to an existing table
and this column should have an explicitely defined default value, for
example "Y" or "N".

Unfortunately, Ingres' "alter table add column" statement cannot do
not null default "N"

"alter table add column" can only do
not null with default

My intention was to work around the problem by running "alter table add
column" and then "alter table alter column".

Any way to achieve my goal without using copying out, dropping,
recreating the table?

Regards
Gerhard


Reply With Quote
  #5  
Old   
Betty & Karl Schendel
 
Posts: n/a

Default Re: [Info-ingres] Ingres 3.0.2, alter table... alter column...,strange results - 09-07-2005 , 08:30 AM



At 2:50 PM +0200 9/7/05, Gerhard Hofmann wrote:
Quote:
I am the original poster of this thread, maybe I should have
described my problem in detail.

We have a Java / JDBC based application that should - in a case of
software updates - perform all necessary table structure changes so
that software version and table structures will always match.

In some cases it will be necessary to add a column to an existing
table and this column should have an explicitely defined default
value, for example "Y" or "N".

Unfortunately, Ingres' "alter table add column" statement cannot do
not null default "N"

"alter table add column" can only do
not null with default

My intention was to work around the problem by running "alter table
add column" and then "alter table alter column".

Any way to achieve my goal without using copying out, dropping,
recreating the table?
Not at present.

I suspect that what we want is an alter table variant that really does
rewrite all the rows when you do alter table add column.
Then you could alter table add column not null [not default initial <value>]
or [with default <value>] and it would initialize the column values.

The hard part is that I'd probably want to implement it within the context
of a modify as well, to avoid logfile overflow problems and row versioning.
That would be nontrivial. (doing it as an alter followed by an update
is not trivial either, but it's simpler. Unfortunately it would be likely
to blow the transaction log for large tables.)

Karl


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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.