%
% SECONDO SQL-Dialekt
%
%

\begin{align*}
&\texttt{sql-clause} &\texttt{-->}\quad &\op{let} \texttt{objectname mquery.}\\
&&|&\op{let}(\texttt{objectname, mquery, secondo-rest-query}).\\
&&|&\op{sql}\ \texttt{mquery.}\\
&&|&\op{sql}(\texttt{mquery, secondo-rest-query}).\\[1em]
&\texttt{aggr} &\texttt{-->}\quad &\texttt{groupattr}\ |\ \texttt{groupattr} \op{as} \texttt{newname}\ |\ \texttt{aggr2}\\[1em]
&\texttt{aggr2} &\texttt{-->}\quad &\op{count}(\texttt{distinct-clause *}) \op{as} \texttt{newname}\\
&&|&\operatorname{aggrop}(\texttt{ext-attr-expr}) \op{as} \texttt{newname}\\
&&|&\op{aggregate}(\texttt{ext-attr-expr, aggrfun, datatype, datatype-\textit{constant}})\\
&&&\op{as} \texttt{newname}\\[1em]
&\texttt{aggrop} &\texttt{-->}\quad &\op{min}|\op{max}|\op{sum}|\op{avg}|\op{extract}|\op{count}\\[1em]
&\texttt{aggr-clause} &\texttt{-->}\quad &\texttt{aggr}\ |\ \texttt{[aggr, aggr-list]}\\[1em]
&\texttt{aggr-fun} &\texttt{-->}\quad &\textbf{(\begin{math}*\end{math})} |\textbf{(+)}| \op{union\_new}|\op{intersection\_new}|\dots\\
&&&\text{\% any name \textit{fun} of a binary \textsc{Secondo}-operator or function object}\\
&&&\text{with syntax}\ fun:T \times T\operatorname{\texttt{-->}}T\\
&&&\text{which should be associative and commutative. Infix-operators}\\
&&&\text{must be enclosed in round parentheses.}\\
&\texttt{aggr-list} &\texttt{-->}\quad &\texttt{aggr}\ |\ \texttt{aggr, aggr-list}\\
&\texttt{all-expr} &\texttt{-->}\quad &\texttt{attr-}\textit{expr}\ \op{<}\ \op{all}\texttt{(subquery)} \\
&&|&\texttt{attr-}\textit{expr}\ \op{<=}\ \op{all}\texttt{(subquery)} \\
&&|&\texttt{attr-}\textit{expr}\ \op{=>}\ \op{all}\texttt{(subquery)} \\
&&|&\texttt{attr-}\textit{expr}\ \op{>}\ \op{all}\texttt{(subquery)} \\
&\texttt{any-expr} &\texttt{-->}\quad &\texttt{attr-}\textit{expr}\ \op{<}\ \op{any}\texttt{(subquery)} \\
&&|&\texttt{attr-}\textit{expr}\ \op{<=}\ \op{any}\texttt{(subquery)} \\
&&|&\texttt{attr-}\textit{expr}\ \op{=}\ \op{any}\texttt{(subquery)} \\
&&|&\texttt{attr-}\textit{expr}\ \op{=>}\ \op{any}\texttt{(subquery)} \\
&&|&\texttt{attr-}\textit{expr}\ \op{>}\ \op{any}\texttt{(subquery)} \\
\end{align*}

\begin{align*}
&\texttt{attr} &\texttt{-->}\quad &\texttt{attrname}\ |\ \texttt{var:attrname}\\
&\texttt{attr-list} &\texttt{-->}\quad &\texttt{attr}\ |\ \texttt{attr, attr-list}\\
&\texttt{attrname}&\texttt{-->}\quad &\texttt{id}									\\
&\texttt{column}&\texttt{-->}\quad &\texttt{newname : datatype}									\\
&\texttt{columnlist}&\texttt{-->}\quad &\texttt{column }	|\texttt{ column, column-list}								\\
&\texttt{createquery}&\texttt{-->}\quad &\op{create} \op{table}\ \texttt{newname}\ \op{colums}\ \texttt{[columnlist]} 	\\
&&|&\op{create} \op{index} \op{on}\ \texttt{newname}\ \op{columns}\ \texttt{index-clause}								\\
&\texttt{datatype}&\texttt{-->}\quad &\op{int}	|\op{real}	|\op{bool}	|\op{string}	|\op{line}	|\op{points}	|\texttt{mpoint}	|\op{uregion}	|\texttt{\dots}\\
&&&\text{\% any name of a SECONDO-datatype}	\\
&\texttt{deletequery}&\texttt{-->}\quad &\op{delete}\ \op{from}\ \texttt{rel-clause where-clause}									\\
&\texttt{distinct-clause}&\texttt{-->}\quad &\op{all}	|\op{distinct}	|\op{$\epsilon$}							\\
&\texttt{dropquery}&\texttt{-->}\quad &\op{drop}\ \op{table}\ \texttt{relname} \\
&&|&\op{drop}\ \op{index}\ \texttt{indexname}	\\
&&|&\op{drop}\ \op{index}\ \op{on}\ \texttt{relname indexclause}							\\
&\texttt{exists-expr}&\texttt{-->}\quad &\op{exists}\texttt{(subquery)} \\
&\texttt{exists-not-expr}&\texttt{-->}\quad &\op{not(exists}\texttt{(subquery))} \\
&\texttt{ext-attr}&\texttt{-->}\quad &\texttt{distinct-clause attr}									\\
&\texttt{ext-attr-expr}&\texttt{-->}\quad &\texttt{distinct-clause attr-}\textit{expr}									\\
&\texttt{first-clause}&\texttt{-->}\quad &\op{first}\ \texttt{int-}\textit{constant }	|\op{last}\ \texttt{int-}\textit{constant}	|\op{$\epsilon$}							\\
&\texttt{groupattr}&\texttt{-->}\quad &\texttt{attr}									\\
&\texttt{groupattr-list}&\texttt{-->}\quad &\texttt{groupattr }	|\texttt{ groupattr, groupattr-list }	|\op{$\epsilon$}							\\
&\texttt{groupby-clause}&\texttt{-->}\quad &\op{groupby}\ \texttt{[groupattr-list]}	|\op{groupby}\ \texttt{groupattr}								\\
&\texttt{id}&\texttt{-->}\quad &\texttt{\% any valid Prolog constant-identifier without an} \\
&&&\text{underscore-character}									\\
&\texttt{in-expr}&\texttt{-->}\quad &\texttt{attr-}\textit{expr}\ \op{in}\ \texttt{(value-list)}\ |\ \texttt{attr-}\textit{expr}\ \op{in}\ \texttt{(subquery)}\\
&\texttt{indexname}&\texttt{-->}\quad &\texttt{id}									\\
&\texttt{indextype}&\texttt{-->}\quad &\op{btree}	|\op{rtree}	|\op{hash}	|\texttt{\dots} \\
&&&\text{\% any name of a logical index type}						\\
&\texttt{index-clause}&\texttt{-->}\quad &\texttt{attrname }	|\ \texttt{attrname}\ \op{indextype}\ \texttt{indextype}								\\
&\texttt{insertquery}&\texttt{-->}\quad &\op{insert}\ \op{into}\ \texttt{rel}\ \op{values}\ \texttt{value-list}	|\op{insert}\ \op{into}\ \texttt{rel query}								\\
&\texttt{mquery}&\texttt{-->}\quad&\texttt{query}	\\
&&|&\texttt{insertquery}	\\
&&|&\texttt{deletequery}	\\
&&|&\texttt{updatequery}	\\
&&|&\texttt{createquery}	\\
&&|&\texttt{dropquery}	\\
&&|&\op{union}\texttt{[query-list]}	\\
&&|&\op{intersection}\texttt{[query-list]}		\\
&\texttt{newname}&\texttt{-->}\quad &\texttt{id} \\
&&&\text{\% where id is not already defined within the database or the} \\
&&&\text{current query} \\
\end{align*}

\begin{align*}
&\texttt{not-in-expr}&\texttt{-->}\quad &\texttt{attr-}\textit{expr}\ \op{not in}\ \texttt{(value-list)}\\									\\
&\texttt{orderattr}&\texttt{-->}\quad &\texttt{attrname}\	|\ \texttt{attrname}\ \op{asc}\	|\ \texttt{attrname}\ \op{desc}\ 	|\ \op{distance}\texttt{(id, id)}						\\
&\texttt{orderattr-list}&\texttt{-->}\quad &\texttt{orderattr }	|\texttt{ orderattr, orderattr-list}								\\
&\texttt{orderby-clause}&\texttt{-->}\quad &\op{orderby}\ \texttt{[orderattr-list] }	|\op{ orderby}\ \texttt{orderattr}\	|\ \op{$\epsilon$}	\\
&\texttt{pred}&\texttt{-->}\quad &\texttt{attr-}\textit{boolexpr}\\
&&|&\texttt{all-expr}\\
&&|&\texttt{any-expr}\\
&&|&\texttt{exists-expr}\\
&&|&\texttt{exists-not-expr}\\
&&|&\texttt{in-expr}\\
&&|&\texttt{not-in-expr}							\\
&\texttt{pred-list}&\texttt{-->}\quad &\texttt{pred }	|\texttt{ pred, pred-list}								\\
&\texttt{query}&\texttt{-->}\quad &\op{select}\ \texttt{distinct-clause sel-clause}\ \op{from}\ \texttt{rel-clause } \\
&&& \texttt{where-clause orderby-clause first-clause}	\\
&&|&\op{select}\ \texttt{aggr-clause}\ \op{from}\ \texttt{rel-clause where-clause }\\
&&&\texttt{groupby-clause orderby-clause first-clause}								\\
&\texttt{query-list}&\texttt{-->}\quad &\texttt{query }	|\texttt{ query, query-list}								\\
&\texttt{rel}&\texttt{-->}\quad &\texttt{relname }	|\texttt{ relname}\ \op{as}\ \texttt{var}\ |\ \texttt{subquery-table}\ \op{as}\ \texttt{newname}									\\
&\texttt{rel-clause}&\texttt{-->}\quad &\texttt{rel }	|\texttt{ [rel-list]}								\\
&\texttt{rel-list}&\texttt{-->}\quad &\texttt{rel }	|\texttt{ rel, rel-list}								\\
&\texttt{relname}&\texttt{-->}\quad &\texttt{id}									\\
&\texttt{result}&\texttt{-->}\quad &\texttt{attr }	|\texttt{ attr-expr as newname}\ |\ \texttt{subquery-aggr}\ \op{as}\ \texttt{newname}	\\
&\texttt{result-list}&\texttt{-->}\quad &\texttt{result }	|\texttt{ result, result-list}								\\
&\texttt{secondo-rest-query}&\texttt{-->}\quad &\texttt{'text'} \\
&&&\text{\% any valid subexpression in SECONDO executable language}									\\
&\texttt{sel-clause}&\texttt{-->}\quad &\texttt{*}	\\
&&|&\texttt{ result }	\\
&&|&\texttt{ [result-list] }	\\
&&|&\op{count}\texttt{(distinct-clause *)}	\\
&&|&\texttt{aggrop(ext-attr-expr) }	\\
&&|&\op{aggregate}\texttt{(ext-attr-expr, aggrfun, datatype, datatype-}\\
&&&\textit{constant)}				\\
&\texttt{subquery}&\texttt{-->}\quad &\texttt{subquery-aggr}\\
&&|&\texttt{subquery-correlated} \\
&&|&\texttt{subquery-simple}\\
&\texttt{subquery-aggr}&\texttt{-->}\quad &\text{\% any query with aggr-clause but without first-clause, }\\
&&&\text{groupby-clause and orderby-clause}\\
\end{align*}

\begin{align*}
&\texttt{subquery-correlated}&\texttt{-->}\quad &\text{\% any query without first-clause, groupby-clause }\\
&&&\text{and orderby-clause which uses an attribute of a relation of an} \\
&&&\text{outer query block} \\
&\texttt{subquery-simple}&\texttt{-->}\quad &\text{\% any query without aggr-clause, first-clause, groupby-clause }\\
&&&\text{and orderby-clause with a single result column} \\
&\texttt{subquery-table}&\texttt{-->}\quad &\text{\% any query without aggr-clause, first-clause, groupby-clause }\\
&&&\text{and orderby-clause} \\
&\texttt{text}&\texttt{-->}\quad &\text{\% any sequence of characters, that completes the optimized} \\
&&&\text{query to a valid expression in } \textsc{Secondo} \text{ executable language}									\\
&\texttt{transform}&\texttt{-->}\quad &\texttt{attrname = update-expression}									\\
&\texttt{transform-clause}&\texttt{-->}\quad &\texttt{transform }	|\texttt{ [transform-list]}								\\
&\texttt{transform-list}&\texttt{-->}\quad &\texttt{transform }	|\texttt{ transform, transform-list}								\\
&\texttt{update-expression}&\texttt{-->}\quad &\texttt{\% a fixed value, or an operation calculating a value}									\\
&\texttt{updatequery}&\texttt{-->}\quad &\op{update}\ \texttt{rel}\ \op{set}\ \texttt{transform-clause where-clause}									\\
&\texttt{var }&\texttt{-->}\quad &\texttt{id}									\\
&\texttt{value}&\texttt{-->}\quad &\text{\% an integer, boolean or string value in prolog}									\\
&\texttt{value-list}&\texttt{-->}\quad &\texttt{value }	|\texttt{ value, value-list}								\\
&\texttt{where-clause}&\texttt{-->}\quad &\op{where}\ \texttt{[pred-list] }	|\ \op{where}\ \texttt{pred } |\ \op{$\epsilon$}							\\			
\end{align*}

%
% EOF
%
%