Joe Celko's SQL for Smarties: Advanced SQL Programming, Third Edition

Chapter 24: Regions, Runs, Gaps, Sequences, and Series

Overview

Tables do not have an ordering to their rows. Yes, the physical storage of the rows in many SQL products might be ordered if the product is built on an old file system. More modern implementations might not construct and materialize the result set rows until the end of the query execution.

The first rule in a relational database is that all relationships are shown in tables by values in columns. This means that things involving an ordering must have a table with at least two columns. One column, the sequence number, is the primary key; the other column has the value that holds that position in the sequence.

The sequence column has consecutive unique integers, without any gaps in the numbering. Examples of this sort of data would be ticket numbers, time series data taken at fixed intervals, and the like. The ordering of those identifiers carries some information, such as physical or temporal location. A subsequence is a set of consecutive unique identifiers within a larger containing sequence that has some property. This property is usually consecutive numbering.

For example, given the data

CREATE TABLE List(seq_nbr INTEGER NOT NULL UNIQUE,  val INTEGER NOT NULL UNIQUE);INSERT INTO ListVALUES (1, 99), (2, 10), (3, 11), (4, 12), (5, 13), (6, 14), (7, 0);

You can find subsequences of size three that follow the rule (10, 11, 12), (11, 12, 13), and (12, 13, 14) but the...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Data Security Software
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.