db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kristian Waagan <Kristian.Waa...@Sun.COM>
Subject Re: generated always as identity
Date Thu, 05 Mar 2009 21:31:06 GMT
George H wrote:
> Have you tried setting the start and increment values of the identity
> statement like
> 
> GENERATED ALWAYS AS IDENTITY(START WITH x, INCREMENT BY y )
> 
> where x is the last auto_increment number from mysql and y is well the
> step number to increment by.
> 
> --
> George H
> george.dma@gmail.com
> 
> 
> 
> On Thu, Mar 5, 2009 at 6:44 PM,  <aponb@gmx.at> wrote:
>> I need to replicate data from mysql to derby. I have the init script for the
>> empty derby db. Some tables have columns, which provide generated keys.
>> These tables are created like this:
>> create table foo (foo_id bigint not null generated always as identity
>> primary key, ... );
>>
>> If I try to replicate my data from the other database to derby, it won't
>> work because derby wants to generate the key for foo_id. So my idea was to
>> create all tables with these columns without the "generated always as
>> identity" statement. Then to import all data. And after then to alter the
>> column again.
>>
>> The import worked, but what I couldn't do was to add the statement
>> "generated always as identity" to the column foo_id.
>> Does anybody know how can I do that?

Hello,

As far as I know, you cannot alter the column in such a way.

Can you use GENERATED BY DEFAULT AS IDENTITY instead?
If so, you have to adjust the identity value after the initial data has 
been imported, as George described in his answer, to make sure you don't 
get any duplicate values.
It may also be wise to make sure your insertion code properly handles 
duplicate primary key exceptions.


HTH,
-- 
Kristian

>>
>>


Mime
View raw message