Menu

Relation constructor questions

2007-02-15
2013-04-18
  • Lennart Jonsson

    Lennart Jonsson - 2007-02-15

    I started playing around with Dee and have two reflections.

    1. If I create a relation like:

    >>> from Dee import *
    >>> X = Relation(['A'],[(1)])
    >>> X
    Relation(('A',),
    [],
    {'PK':(Key, None)})

    I.e. it has no body. I would have expected X to look like:

    >>> X
    Relation(('A'),
    [Tuple(A=1)],
    {'PK':(Key, None)})

    Is it intended this way?

    2. Do you think it would be a good idea to always store the heading in upper (or lower) case? I.e.

    >>> X = Relation(['A','b'],[(1,1)])
    >>> Y = Relation(['a','B'],[(1,1)])
    >>> X==Y
    True

    I can imagine some confusion in a situation like:

    >>> Student = Relation(['StudentId', 'Whatever'],[(1,'a'),(2,'b')])
    >>> Mark = Relation(['Studentid','Mark'],[(1,'G')])
    >>> Student & Mark
    Relation(('Studentid', 'StudentId', 'Whatever', 'Mark'),
    [Tuple(Studentid=1, StudentId=1, Whatever='a', Mark='G'), Tuple(Studentid=1, StudentId=2, Whatever='b', Mark='G')],
    {'PK':(Key, None)})

    Regards
    /Lennart

     
    • Lennart Jonsson

      Lennart Jonsson - 2007-02-16

      Ah, yes. One has to use a tuple. Silly me :-)

      >>> X = Relation(['A'],[(1,)])
      >>> X
      Relation(('A',),
      [Tuple(A=1)],
      {'PK':(Key, None)})

      Perhaps it would be a good idea to throw an error in the case of:

      >>> X = Relation(['A'],[(1)])
      >>> X
      Relation(('A',),
      [],
      {'PK':(Key, None)})

      Regards
      /Lennart

       
    • Greg Gaughan

      Greg Gaughan - 2007-02-18

      1. Indeed, a tuple is needed so in Python the trailing comma in (1,) is important. I like your suggestion of raising an error if (1) is passed - I'll add it to the todo list.

      2. It would help if you use a consistent way of naming the heading attributes. I tend to use Pascal case, but I don't think it's something that should be enforced or matched case-insensitively since Python is case sensitive with its names. Perhaps some kind of pre-parser, or maybe a verbose-checking-mode, to check the sanity of a schema or set of expressions would be useful. This could spot mis-spellings, and joins where the column names were probably meant to match but didn't, and unintended cartesian joins etc.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.