Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to plan a framework for relational algebra using the Dataset capability of Mathematica 10.

In the work of Date and Darwen, there are two concepts known as TABLE_DEE and TABLE_DUM. TABLE_DEE is a relation with a (column) header but no rows, whereas TABLE_DUM is simply:

Dataset[{}]

How might I create a TABLE_DEE with Dataset--a table with headers, but no data? I feel this would allow a framework for performing orthodox relational database operations.

share|improve this question

2 Answers 2

up vote 10 down vote accepted

You have to use the undocumented (and subject-to-change) syntax for specifying a type or schema:

Needs["TypeSystem`"];
Dataset[
  {}, 
  Vector @ Struct[
    "field1" -> Atom[Integer], 
    "field2" -> Atom[String]
  ]
]

Replace the contents of the inner Struct as you see fit (you can always use TypeSystem`DeduceType on a chunk of data obeying your desired schema to see more examples of these type expressions).

share|improve this answer
2  
Your code produces an error message Dataset::data: Data does not conform to type <...> and does not produce "a table with headers, but no data" (citing the question). –  Alexey Popkov Jul 12 at 8:35
4  
@AlexeyPopkov I'm sorry, you have to write Needs["TypeSystem"]` before evaluating my code. I've updated my answer. –  Taliesin Beynon Jul 13 at 0:34
1  
@TaliesinBeynon Thanks for your reply. I gathered that you are the author of this code. I'm really happy about this functionality, especially the ability to have data sets inside of data sets (relations inside of relations). –  Eric Brown Jul 13 at 1:28

We can create a table with a header and no rows like this:

Dataset[{<|"header" -> 1|>}] @ Select[False &]

dataset screenshot

This uses only documented functionality.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.