Grammar of Temporal SQL used in TimeDB 2.0 Demo
===============================================


statement   ::= (query | ddl | dml | control) ';'


Query
-----

timeFlag ::= [ 'nonsequenced' ] 'validtime' [ scalarExp ]

coal ::= '(' 'period' ')'


query       ::= [ timeFlag ] queryExp
queryExp    ::= queryTerm { ('union' | 'except') queryTerm }
queryTerm   ::= queryFactor { 'intersect' queryFactor }
queryFactor ::= '(' query ')' [ coal ] | sfw

sfw         ::= 'select' selectItemList 
                'from' tableRefList 
                [ 'where' condExp ]


selectItemList ::= '*' | selectItem { ',' selectItem }
selectItem     ::= scalarExp [ alias ]

tableRefList ::= tableRef { ',' tableRef }
tableRef     ::= '(' query ')' [ coal ] alias [ colList ] | 
                 identifier [ coal ] [ alias ]

alias ::= ['as'] identifier

condExp          ::= condTerm { 'or' condTerm }
condTerm         ::= condFactor { 'and' condFactor }
condFactor       ::= [ 'not' ] simpleCondFactor
simpleCondFactor ::= '(' condExp ')' | 
                     scalarExp condOp scalarExp
                     
condOp ::= '<' | '>' | '<=' | '>=' | '<>' | '=' |
           'precedes' | 'overlaps' | 'meets' | 'contains'              


scalarExp    ::= term { ('+' | '-') term }
term         ::= factor { ('*' | '/') factor }
factor       ::= [ ('+' | '-') ] simpleFactor
simpleFactor ::= colRef                  | 
                 const                   | 
                 '(' scalarExp ')'       |
                 'abs' '(' scalarExp ')'

colRef ::= identifier [ '.' identifier ]

const ::= integer        |
          float          |
          ''' string ''' |
          interval       |
          event          | 
          span


interval    ::= 'validtime' '(' identifier ')' | 
                'period' intervalExp |
                'period' '(' scalarExp ',' scalarExp ')'
intervalExp ::= '[' time '-' time ')'
time        ::= timeDBDate | eventExp


event    ::= ( 'begin' | 'end' ) '(' scalarExp ')'                |
             ( 'first' | 'last' ) '(' scalarExp ',' scalarExp ')' |
             eventExp

eventExp ::= 'now'                       |
             'beginning'                 | 
             'forever'                   |
             'date' dateString           |
             'date' timeDBDate           |
             'timestamp' timestampString

dateString      ::= ''' YYYY '-' MM '-' DD '''
timestampString ::=  ''' YYYY '-' MM '-' DD ' ' HH ':' MM ':' SS '''
timeDBDate      ::= YYYY [ '/' MM [ '/' DD 
                    [ '~' HH [ ':' MM [ ':' SS ]]]]] 


span      ::= 'interval' spanExp
spanExp   ::= integer qualifier { integer qualifier }
qualifier ::= 'year'   | 
              'month'  |
              'day'    |
              'hour'   |
              'minute' |
              'second'




Data Definition
---------------

ddl ::=  ddlTable | 'drop' 'table'
        
ddlTable  ::= 'create' 'table' identifier '(' colDefList ')' [ 'as' 'validtime' ] 

colDefList ::= colDef { ',' colDef }
colDef     ::= identifier dataType

colList ::= col { ',' col }
col     ::= identifier

dataType ::= 'number'  [ typeLength ] |  /* Oracle */
             'numeric' [ typeLength ] |  /* Sybase */
             'smallint'               |  /* Cloudscape's JBMS */
             'longint'                |  /* Cloudscape's JBMS */
             'integer'                |
             'real'                   |
             'float'                  |
             'interval'               |
             'date'                   |
             'period'                 |
             'char'    [ typeLength ] | 
             'varchar' [ typeLength ]

typeLength ::= '(' integer ')'



Data Manipulation
-----------------
           
dml ::= [ timeFlag ] insert

insert ::= 'insert' 'into' identifier valExp
valExp ::= 'values' '(' valList ')'
           



Control
-------

control ::= 'commit' | 'rollback'
            
 
July 27, 1998
