Xiao Yafeng wrote:
I don't think an array of hashes and a hash of arrays could perfectly
represent a Table type.
There are several important facts of a relational model:unordered
columns and tupples, various constraints on columns. E.g. how can we
represent multi-unique constraints as an array of hashes?
Well, a Set/Array/Hash of Hash/Mapping very well could represent the actual
value of a relational table, which is simply a set of tuples where all tuples
have the same number of attributes/columns and the attrs/cols all have the same
names. (While the order of rows or columns is not significant as you say, you
can still implement them over an ordered type like an Array; or you can just use
Set/Hash/Mapping which are unordered.)
That alone is all you need as the input or output of essentially all the
relational operators.
Having type constraints on individual columns is strictly optional, though
highly useful; there's no reason that a single column *has* to be just strings
or just integers; see the SQLite DBMS (or Perl itself by default) as an example
of such non-strictness; this doesn't break the relational model. Only the
relational ungroup and unwrap operations require a bit more strictness, since
they require consistent table or tuple typed attributes to work.
As for defining key/unique constraints, that does require an extra piece of
information to be stored ... and so does defining type constraints on individual
columns ... and this is why its useful to have a library to wrap the
functionality, as it can remember those details for you. Set::Relation
currently does keys but not column types; Muldis::Rosetta will do both; either
way, those constraints are optional, though highly recommended in practice.
-- Darren Duncan
On 4/4/09, Timothy S. Nelson <wayl...@wayland.id.au> wrote:
On Sat, 4 Apr 2009, Xiao Yafeng wrote:
3. Could I define primary key for a bag variable?
All items in a Bag are "primary keys", but there's no data additional
data associated with it.
I mean whether I can see Set as a table and Bag as a table with a
unique constraint? like:
subset test of Bag(test_name Str, test_ID Int, primary
key(test_ID))
In the meantime, a table would need to be represented as an array of
hashes, or a hash of arrays.