Chapter 12. Group and Ungroup Views

Updating groups

Don’t need no loops


I turn now to the question of updating through the relational grouping and ungrouping operators (GROUP and UNGROUP, in Tutorial D). Since you might not be familiar with those operators, I’ll begin with a brief tutorial.

The Group and Ungroup Operators

Consider the relations shown in Figure 12-1, which we can take to be the current values of two relvars called SP and SPQ, respectively. Of course, relvar SP is just the shipments relvar from our usual suppliers-and-parts database.

Relvars SP and SPQ—sample values
Figure 12-1. Relvars SP and SPQ—sample values

Now, I hope it’s at least intuitively obvious that we have information equivalence here once again[119] (certainly the relations shown in the figure both represent the exact same information).

Now, with regard to those two relations, the one on the left of the figure is just a reduced version of our usual sample value for relvar SP, while the one on the right is what we get if we evaluate the following expression on that sample SP value:


Aside: In fact the GROUP invocation just shown is logically equivalent to a certain EXTEND invocation—to be specific, the invocation EXTEND SP{SNO}:{PQ := s!!SP}, where !!SP denotes a certain image relation[120]—and there are reasons to prefer this EXTEND formulation over its GROUP equivalent. Detailed discussion of such matters ...

Get View Updating and Relational Theory now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.