comparison doc/manual.tex @ 549:39282473d38f

Query syntax
author Adam Chlipala <adamc@hcoop.net>
date Sun, 07 Dec 2008 12:02:54 -0500
parents 8e615bb605c9
children 11e150300ba0
comparison
equal deleted inserted replaced
548:b3b06fef7bb5 549:39282473d38f
1243 One last useful function is for aborting any page generation, returning some XML as an error message. This function takes the place of some uses of a general exception mechanism. 1243 One last useful function is for aborting any page generation, returning some XML as an error message. This function takes the place of some uses of a general exception mechanism.
1244 $$\begin{array}{l} 1244 $$\begin{array}{l}
1245 \mt{val} \; \mt{error} : \mt{t} ::: \mt{Type} \to \mt{xml} \; [\mt{Body}] \; [] \; [] \to \mt{t} 1245 \mt{val} \; \mt{error} : \mt{t} ::: \mt{Type} \to \mt{xml} \; [\mt{Body}] \; [] \; [] \to \mt{t}
1246 \end{array}$$ 1246 \end{array}$$
1247 1247
1248
1249 \section{Ur/Web Syntax Extensions}
1250
1251 Ur/Web features some syntactic shorthands for building values using the functions from the last section. This section sketches the grammar of those extensions. We write spans of syntax inside brackets to indicate that they are optional.
1252
1253 \subsection{SQL}
1254
1255 \subsubsection{Queries}
1256
1257 $$\begin{array}{rrcll}
1258 \textrm{Queries} & Q &::=& (q \; [\mt{ORDER} \; \mt{BY} \; (E \; [D],)^+] \; [\mt{LIMIT} \; N] \; [\mt{OFFSET} \; N]) \\
1259 \textrm{Pre-queries} & q &::=& \mt{SELECT} \; P \; \mt{FROM} \; T,^+ \; [\mt{WHERE} \; E] \; [\mt{GROUP} \; \mt{BY} \; p,^+] \; [\mt{HAVING} \; E] \\
1260 &&& \mid q \; R \; q \\
1261 \textrm{Relational operators} & R &::=& \mt{UNION} \mid \mt{INTERSECT} \mid \mt{EXCEPT}
1262 \end{array}$$
1263
1264 $$\begin{array}{rrcll}
1265 \textrm{Projections} & P &::=& \ast & \textrm{all columns} \\
1266 &&& p,^+ & \textrm{particular columns} \\
1267 \textrm{Pre-projections} & p &::=& t.f & \textrm{one column from a table} \\
1268 &&& t.\{\{c\}\} & \textrm{a record of colums from a table (of kind $\{\mt{Type}\}$)} \\
1269 \textrm{Table names} & t &::=& x & \textrm{constant table name (automatically capitalized)} \\
1270 &&& X & \textrm{constant table name} \\
1271 &&& \{\{c\}\} & \textrm{computed table name (of kind $\mt{Name}$)} \\
1272 \textrm{Column names} & f &::=& X & \textrm{constant column name} \\
1273 &&& \{c\} & \textrm{computed column name (of kind $\mt{Name}$)} \\
1274 \textrm{Tables} & T &::=& x & \textrm{table variable, named locally by its own capitalization} \\
1275 &&& x \; \mt{AS} \; t & \textrm{table variable, with local name} \\
1276 &&& \{\{e\}\} \; \mt{AS} \; t & \textrm{computed table expression, with local name} \\
1277 \textrm{SQL expressions} & E &::=& p & \textrm{column references} \\
1278 &&& X & \textrm{named expression references} \\
1279 &&& \{\{e\}\} & \textrm{injected native Ur expressions} \\
1280 &&& \{e\} & \textrm{computed expressions, probably using $\mt{sql\_exp}$ directly} \\
1281 &&& \mt{TRUE} \mid \mt{FALSE} & \textrm{boolean constants} \\
1282 &&& \ell & \textrm{primitive type literals} \\
1283 &&& \mt{NULL} & \textrm{null value (injection of $\mt{None}$)} \\
1284 &&& E \; \mt{IS} \; \mt{NULL} & \textrm{nullness test} \\
1285 &&& n & \textrm{nullary operators} \\
1286 &&& u \; E & \textrm{unary operators} \\
1287 &&& E \; b \; E & \textrm{binary operators} \\
1288 &&& \mt{COUNT}(\ast) & \textrm{count number of rows} \\
1289 &&& a(E) & \textrm{other aggregate function} \\
1290 &&& (E) & \textrm{explicit precedence} \\
1291 \textrm{Nullary operators} & n &::=& \mt{CURRENT\_TIMESTAMP} \\
1292 \textrm{Unary operators} & u &::=& \mt{NOT} \\
1293 \textrm{Binary operators} & b &::=& \mt{AND} \mid \mt{OR} \mid \neq \mid < \mid \leq \mid > \mid \geq \\
1294 \textrm{Aggregate functions} & a &::=& \mt{AVG} \mid \mt{SUM} \mid \mt{MIN} \mid \mt{MAX} \\
1295 \textrm{Directions} & D &::=& \mt{ASC} \mid \mt{DESC} \\
1296 \textrm{SQL integer} & N &::=& n \mid \{e\} \\
1297 \end{array}$$
1298
1299 Additionally, an SQL expression may be inserted into normal Ur code with the syntax $(\mt{SQL} \; E)$ or $(\mt{WHERE} \; E)$.
1300
1301
1248 \end{document} 1302 \end{document}