body { margin:0px; background-color:#fff } img { margin:0px; border-style:none } button { margin:0px; border-style:none; padding:0px; background-color:transparent; vertical-align:top } p:first-child { margin-top:0px } table { empty-cells:hide } .f-sp { font-size:1px; visibility:hidden } .f-lp { margin-bottom:0px } .f-x1 { } .f-x2 { } .f-x3 { } a:visited { color:#8b0000; text-decoration:underline } .capsub { color:#808080; font-weight:bold; text-transform:uppercase; letter-spacing:2.4px } .style31 { color:#000 } .style38 { color:#000; font-style:italic } .code { color:#000; font-family:monospace } .style36 { color:#000; font-weight:bold } .style21 { margin-left:0px; margin-right:0px; text-align:center; margin-top:0px; margin-bottom:0.1px } .style52 { color:#000; margin-left:0px; margin-right:0px; text-align:center; margin-top:0px; margin-bottom:0.1px } .bulletlist { margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0.1px } .style32 { color:#000 } .style55 { color:#000; margin-left:0px; margin-right:0px; text-align:center; margin-top:0px; margin-bottom:0.1px } .style53 { color:#000; margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0.1px } .style9 { margin-left:0px; margin-right:0px; margin-top:0px; margin-bottom:0.1px } .style34 { color:#000; font-weight:bold } .style46 { color:#000; font-style:italic } .rightaligned { margin-left:0px; margin-right:0px; text-align:right; margin-top:0px; margin-bottom:0.1px } .small { color:#000; font-size:90% } .style42 { color:#000; font-weight:bold; font-size:90% } .style33 { color:#808080; font-style:italic; font-size:90% } .style54 { color:#808080; font-style:italic; font-size:90%; margin-left:0px; margin-right:0px; text-align:center; margin-top:0px; margin-bottom:0.1px } .footer { color:#808080; font-size:90% } .FWExtra { } .FWExtra a:link { text-decoration: none; } .FWExtra a:active { text-decoration: none; } .FWExtra a:visited { text-decoration: none; } .FWExtra a:hover { text-decoration: underline; } -->
an introduction to ratcl - Part 3 The relational algebra operation which has not been mentioned so far is selection. There are in fact three ways to select specific rows from a view: 1. Pick returns all rows for which a non-zero value is supplied: The argument of pick must be a list with as many integers as there are rows in the view. 2. Maprow was shown on the previous page: It can be used to select specific rows. Maprow is quite a general operator, since it can also be used to slice, sort, replicate, or permute rows. 3. Filter is the most general way to select rows. It takes a conditional expression and returns all rows for which the condition is true: Filter offers basically the same flexibility as a SQL "where" clause on a single view. Expression syntax The operators supported in filter expressions consist of the usual mix:
The above list is from highest precedence operator to lowest. Note that "==", "!=", "!", "&&", and "||" are synonyms, matching - as a convenience - the C language. Operands can be integers and column names. A few operations, such as comparisons, also support string operands (delimited by single quotes). Parameters Constant values can also be supplied in Tcl as parameters. Each question mark is replaced by an additional argument supplied to the filter operator: This can avoid the need to quote and escape special characters and can make it easier to parametrize conditions at run-time. Note: parameter values are passed as integers if they look like one, else as strings. To force an explicit type: use "?S" for strings, and "?I" (uppercase-i) for integers. calculated columns Filtering is based on calculated columns (i.e. to decide whether rows are part of the selection). The general form of this is available through the addcol operator: The "C:I" notation indicates that the new C column is of type integer. This example supplies the value "100" as parameter, just to demonstrate the mechanism. Note that addcol is one of a few operators which do not return a new view but actually change a view. More about this on the next page. clean concepts These pages so far should illustrate how Ratcl does relational algebra, and explain the RA prefix of "Ratcl". A lot of effort is being invested in making operations work cleanly and without surprises. They can be applied to any view, produce clearly defined results, and have no side-effects (with a few exceptions such as addcol). Speaking of side-effects. It's time to look at view management and lifetimes in a bit more detail. | ||||||