db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bryan Pendleton (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (DERBY-6852) Allow identity columns to cycle (as defined in SQL:2003)
Date Sat, 18 Jun 2016 16:21:05 GMT

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

Bryan Pendleton commented on DERBY-6852:

I'm sorry, Rick, I've confused myself.

Are you saying that the SQL Standard specifies different behaviors for the
CYCLE option on a SEQUENCE object versus the CYCLE option on a GENERATED column?
That SEQUENCE objects are supposed to cycle around to their start value, but
GENERATED columns are supposed to cycle around to their minimum value?

Or are you saying that the SQL Standard specifies the same behavior for
both SEQUENCE objects and GENERATED columns, and that they are **both**
supposed to cycle around to their start value?

I notice that, in the SequenceGenerator.html spec, there is also this:

If the sequence generator's cycle is exhausted (i.e., it cannot issue a value that meets the
criteria), then a new cycle is created with the current base value set to the minimum value
of SG (if SG is an ascending sequence generator) or the maximum value of SG (if SG is a descending
sequence generator).

That quote seems to talk about the minimum/maximum value, not the start value.

I find reading the SQL standard very hard, and would appreciate your help here.

> Allow identity columns to cycle (as defined in SQL:2003)
> --------------------------------------------------------
>                 Key: DERBY-6852
>                 URL: https://issues.apache.org/jira/browse/DERBY-6852
>             Project: Derby
>          Issue Type: Improvement
>          Components: SQL
>            Reporter: Peter Hansson
>            Assignee: Danoja Dias
> Currently when an IDENTITY column reaches its maximum value it will produce an error.
> For tables that are used as 'transaction logs' or 'event logs' it often makes sense to
let the table automatically start over with the first identity value again when the max is
reached. This would be similar to the CYCLE option on Oracle's SEQUENCE and as defined in
SQL:2003. And Derby is probably used quite often for this purpose, I guess, perhaps even more
than other RDBMSs.
> At the moment every developer have to program their own logic for this.
> I propose to introduce the CYCLE option.
> The idea of CYCLE is based on the assumption that there's been a prior cleanup in the
table rows so that it will be possible to re-use ids that have been used previously. If that
is not the case - and a rollover happens - then a duplicate value error will occur. In this
sense it can be argued that the CYCLE option will trade a _certain_ error for a _potential_
error. Most Derby users would possibly gladly accept such a bargain. In other words: This
option will greatly enhance the usability of IDENTITY columns.
> The current implementation of IDENTITY columns SQL grammar in Derby is a subset of the
SQL:2003 standard which is the first of the SQL standards to define IDENTITY columns. Interestingly
the standard also defines the CYCLE option but this was never implemented in Derby. Also see
[SQL-99 and SQL-2003 features mapped to Derby|https://wiki.apache.org/db-derby/SQLvsDerbyFeatures]
(scroll to T174).
> In other words: The proposal is simply to implement CYCLE as defined in SQL:2003.

This message was sent by Atlassian JIRA

View raw message