[Tfug] "Ordering" tuples in a table

Bexley Hall bexley401 at yahoo.com
Mon Oct 19 18:56:31 MST 2009


Hi,

OK, I'm still trying to adapt my coding style to migrate
code and data structures *out* of the executable and into
an RDBMS.  And I keep stumbling over "little things" of
which I must give up control in order to adopt these
mechanisms.  :<  (dems da brakes!)

In particular, I am trying to figure out how to
adapt to the fact that tuples in the database are
not ordered in the same sense that I can explicitly
order them in a TEXT (or DATA) segment within my code.
(yes, I know you can order them "on output" but the
data themselves are not really "ordered" within the
table -- forget indices, etc)

E.g., the RDBMS doesn't see any difference in the
following two lists:
  Tom Martin
  Bob Jones
  Fred Williams
vs.
  Fred Williams
  Tom Martin
  Bob Jones
And, this is "A Good Thing"!  :-/

But, when building table driven code, you often
implicitly (or explicitly) apply some ordering to 
the contents of your tables!  It allows you to
later explot that ordering to simplify the
algorithms that are *driven* from those tables!

In one such table, I *guarantee* circular definitions
can't exist by imposing the requirement that anything
referenced by a definition must already be defined
(i.e., must exist "earlier" in the table).  So, I
can have:
  x = 3
  ...
  y = x + 2
but this rule prevents:
  x = y - 2
  ...
  y = 5
(i.e., because, at the time x is defined, y does not
yet have a definition).  Otherwise, I could create
anomalies inadvertently like:
  x = y - 2
  ...
  y = X + 2

I can force new entries to the (RDBMS) table to observe this
rule by tying some code to the INSERT method such that any
references the code can't resolve at INSERT-time are
rejected.

However, if the table is eventually *dumped*, there is
no guarantee that rebuilding the table will cause the
tuples to be re-INSERTed in the same order that was
imposed on the original INSERTions.

So, how do you do this?  Consider a record for a
"person" having fields that specify name, birthdate, etc.
In addition, fields that REFERENCE *other* records
defining the "mother" and "father" for that "person".
I.e., how do you refer to a mother who's record doesn't
yet exist??

(I figure *this* sort of thing has to come up "in the
real world"!?)

Thanks!
--don



      




More information about the tfug mailing list