Tutorial
 COMMUNITY
 DEVELOPER CORNER

 HOME ART > Tutorial > SaadaQL WhereRelation

The WhereRelation contains a list of correlation patterns. A correlation pattern is a description of a vector drown by the correlation links of a given relationship (see datamodel) and starting from agiven record.

The WhereRelation statement can contain multiple patterns. All of patterns are ANDed.

 ```WhereRelation{ matchPattern { pattern1 }               matchPattern { pattern2 }               } ```

In the example given before, data having correlation links matching both patterns pattern1 and pattern2 are selected. There is no limitation in the number of patterns contained into the WhereRelation clause.

A relation pattern must contain the relation name at least .

 `matchPattern {Spectra2Src } `

The pattern shown here simply specifies : at least one link of the relationship Spectra2Src. Data correlated by the relationship Spectra2Src with at least one secondary record (a counterpart) match this pattern.

The number of links of the pattern can be refined with the Cardinality . The Cardinality statement must follow the relation name.

 ``` matchPattern {             Spectra2Src             , Cardinality = 3             } ```
• The pattern shown above specifies : 3 links of the relationship Spectra2Src. Data correlated by the relationship Spectra2Src with 3 secondary records match this pattern. The Cardinality function must be unique in a pattern. The first parameter of the Cardinality function is the operator :
 "=" equals to "=" not equals to "<" less than ">" greater than "<=" less than or equal to ">=" greater than or equal to "[]" In (excluded) bounds "[=]" In (included) bounds "][" Out of (excluded) bounds "]=[" Out of included bounds

Operators "[]", "[=]", "][", and "]=[" require 2 operands which must be in ’()’ :

 ``` matchPattern {Spectra2Src             , Cardinality [=] (1,2)             } ```

Relation links can be qualified with user defined numeric values, the link qualifiers. Constraints on qualifiers are set with the functions Qualifier. The first parameter is the qualifier name and the others are similar with those of the Cardinality function. One pattern can contain several Qualifiers functions. They are ANDed

 ```matchPattern {Spectra2Src             , Qualifier{likelihood > 20000}             , Qualifier{pixel_value [] (1,2) }             }```

A relation pattern can also include constrains on the collection attributes of the secondary object with the AssObjAttSaada function. It must be unique in a pattern. It contains an SQL like string similar to the WhereAttributeSaada clause.

 ```matchPattern {Spectra2Src            , AssObjAttSaada{ namesaada like 'LE%' }            }```

The pattern shown above specifies : at least one link of the relationship Spectra2Src pointing to an object with a name begining with ’LE’. The second pattern below selects correlation vectors with 3 links of the relationship Spectra2Src pointing to objects with a name begining with ’LE’..

 ```matchPattern {Spectra2Src            , Cardinality = 3            , AssObjAtt{ namesaada like 'LE%' }            }```

A pattern can also select the classes of the secondary objects :

 ```matchPattern { Spectra2Src             , AssObjClass{Class1, Class2}             }```

The pattern shown above specifies : at least one link of the relationship Spectra2Src pointing to an object of the class Class1 or Class2. Class names must be coma separated. Saada classes can be displayed with the Database Map anchor on the top of any web pages :

If the pattern contains the AssObjClass function with only one class name, constraints on the attributes of this class can be set with the AssObjAttClass function :

 ```matchPattern {Spectra2Src             , AssObjClass{Class1}             , AssObjAttClass{ _BZERO > 32 and _ARCFILER like 'FOR%' }             }```

The function AssObjAttClass is very similar to WhereAttributeClass (see).

Correlation patterns can also uses UCDs or Utypes as for WhereUCD. UCD based constraints in pattern are handled by the operator AssUCD. Utypes based constraints in pattern are handled by the operator AssUTYPE. AssUTYPE. and AssUCD. cannot be used sumultaneously in the same pattern.

 ``` matchPattern {Spectra2Src             , AssUCD{[src.redshift] > 2  [none])}             }```

The table below summarizes all pattern components. Note that each component except Qualifier can figure only once in a pattern.

 `relation  name` Name of the relationship concerned by the pattern. `Cardinality  operator, value` Constraint on the number of links. `Qualifier{ qual.name operator value}` Constraint on a relationship qualifier value. It can be used several times in a pattern. `AssObjAttSaada{ SQL like where clause }` Constraint on the collection attributes of the secondary objects of relationship. `AssObjClass{ classname;,...}` List if accepted classes of the secondary objects of the relationship. Classe names must be in " ". `AssObjAttClass{ SQL like where clause } ` Constraint on the class attributes of the secondary object of the relationship. Can can only be used in patterns containing an AssObjClass with one class. `AssUCD` Constraint on counterpart attributes expressed with UCDs `AssUTYPE` Constraint on counterpart attributes expressed with Utypes
last update 2008-05-13