db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DERBY-3) Identity column not filled consecutively with "insert ... select distinct"
Date Mon, 25 May 2009 18:36:45 GMT

    [ https://issues.apache.org/jira/browse/DERBY-3?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12712767#action_12712767
] 

Knut Anders Hatlen commented on DERBY-3:
----------------------------------------

Just to add another data point, the identity values are consecutive if you put another query
around the select distinct:

ij> insert into temp2 (s) select * from (select distinct s from temp1) t;
4 rows inserted/updated/deleted
ij> select * from temp2;
I          |S         
----------------------
1          |d         
2          |b         
3          |c         
4          |a         

4 rows selected

For some reason, the ordering is different too.

> Identity column not filled consecutively with "insert ... select distinct"
> --------------------------------------------------------------------------
>
>                 Key: DERBY-3
>                 URL: https://issues.apache.org/jira/browse/DERBY-3
>             Project: Derby
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 10.2.1.6
>         Environment: Derby Snapshot svnversion 46005
> or Cloudscape 10.0 GA
> Derby 10.2beta
>            Reporter: Christian d'Heureuse
>            Priority: Minor
>
> When an "insert ... select distinct" is used to fill a table with an identity column,
gaps occur in the identity column. The caps correspond to the rows of the source table that
have been suppressed with "distinct".
> Example:
> create table temp1 (
>    s varchar(10));
> insert into temp1 values 'a','a','a','b','c','c','c','d';
> create table temp2 (
>    i integer not null
>       generated always as identity
>       primary key,
>    s varchar(10));
> insert into temp2 (s)
>    select distinct s from temp1;
> select * from temp2;
> output:
>  1   a
>  4   b
>  5   c
>  8   d

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message