On Fri, 6 Apr 2012 22:34:35 -0700, Mark Phillips
<ma...@phillipsmarketing.biz> declaimed the following in
gmane.comp.python.django.user:
>
> Basically, I have sets of data determined by a foreign key, and I want to
> know the order in which the rows arrive within a data set.
>
IOWs, you don't really need a value incrementing per foreign key...
After all, the primary key already reflects the /order/ of new data
inserts.
In plain SQL, this might be an application for a "group by" the
foreign key, "order by" the primary key. Note that your example is NOT
very clear. "Reset to zero" could result in:
1 1 1 ....
2 1 2 ...
3 2 1 ...
4 1 1 ...
5 2 1 ...
6 2 2 ...
Whereas, ignoring the example "sequence" column, group by/order by
would return
1 1 1 ...
2 1 2 ...
4 1 1 ...
3 2 1 ...
5 2 1 ...
6 2 2 ...
Actually, just an ORDER BY FK, PK would produce the above... GROUP
BY would be used if you need something like counts/avg for each FK set.
Actually, just an ORDER BY FK, PK would produce the above... GROUP
BY would be used if you need something like counts/avg for each FK set.I agree that if the data in the db was entered correctly in the first place, then just ORDER BY on the FK and PK would be sufficient. However, if the user needs to insert some data between sequence #3 and sequence #4, then I have to muck with the primary key of the table, which sounds dangerous.