doc/book/en/annexes/rql/language.rst
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 04 Aug 2011 12:50:58 +0200
branchstable
changeset 7738 e0c86caf5c48
parent 7632 3c9dfc6e820b
child 8017 1df3b5e9d010
permissions -rw-r--r--
[book, rql] update rql langage chapter with new operators and outer join capabilities
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
.. -*- coding: utf-8 -*-
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
.. _RQL:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     5
RQL syntax
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
----------
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     7
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
     8
.. _RQLKeywords:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
     9
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    10
Reserved keywords
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    11
~~~~~~~~~~~~~~~~~
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    12
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    13
::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    14
3686
d44b17016944 [doc] document rql operator ILIKE
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    15
  AND, ASC, BEING, DELETE, DESC, DISTINCT, EXISTS, FALSE, GROUPBY,
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    16
  HAVING, ILIKE, INSERT, LIKE, LIMIT, NOT, NOW, NULL, OFFSET,
3686
d44b17016944 [doc] document rql operator ILIKE
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
    17
  OR, ORDERBY, SET, TODAY, TRUE, UNION, WHERE, WITH
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    18
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    19
The keywords are not case sensitive. You should not use them when defining your
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    20
schema, or as RQL variable names.
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
    21
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    22
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    23
.. _RQLCase:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
    24
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    25
Case
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    26
~~~~
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    27
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    28
* Variables should be all upper-cased.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    29
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    30
* Relation should be all lower-cased and match exactly names of relations defined
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    31
  in the schema.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    32
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    33
* Entity types should start with an upper cased letter and be followed by at least
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    34
  a lower cased latter.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    35
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    36
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    37
.. _RQLVariables:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
    38
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    39
Variables and typing
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    40
~~~~~~~~~~~~~~~~~~~~
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    41
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    42
Entities and values to browse and/or select are represented in the query by
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    43
*variables* that must be written in capital letters.
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
    44
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    45
With RQL, we do not distinguish between entities and attributes. The value of an
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    46
attribute is considered as an entity of a particular type (see below), linked to
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    47
one (real) entity by a relation called the name of the attribute, where the
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    48
entity is the subject and the attribute the object.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    49
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    50
The possible type(s) for each variable is derived from the schema according to
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    51
the constraints expressed above and thanks to the relations between each
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    52
variable.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    53
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    54
We can restrict the possible types for a variable using the special relation
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    55
**is** in the restrictions.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    56
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    57
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    58
Virtual relations
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    59
~~~~~~~~~~~~~~~~~
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    60
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    61
Those relations may only be used in RQL query but are not actual attributes of
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    62
your entities.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    63
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    64
* `has_text`: relation to use to query the full text index (only for entities
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    65
  having fulltextindexed attributes).
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    66
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    67
* `identity`: relation to use to tell that a RQL variable is the same as another
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    68
  when you've to use two different variables for querying purpose. On the
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
    69
  opposite it's also useful together with the :ref:`NOT` operator to tell that two
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    70
  variables should not identify the same entity
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    71
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    72
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    73
.. _RQLLiterals:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
    74
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    75
Literal expressions
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    76
~~~~~~~~~~~~~~~~~~~
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    77
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    78
Bases types supported by RQL are those supported by yams schema. Literal values
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    79
are expressed as explained below:
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    80
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    81
* string should be between double or single quotes. If the value contains a
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    82
  quote, it should be preceded by a backslash '\'
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    83
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    84
* floats separator is dot '.'
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    85
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    86
* boolean values are :keyword:`TRUE` and :keyword:`FALSE` keywords
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    87
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    88
* date and time should be expressed as a string with ISO notation : YYYY/MM/DD
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    89
  [hh:mm], or using keywords :keyword:`TODAY` and :keyword:`NOW`
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    90
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    91
You may also use the :keyword:`NULL` keyword, meaning 'unspecified'.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    92
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    93
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    94
.. _RQLOperators:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
    95
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    96
Operators
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    97
~~~~~~~~~
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    98
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
    99
.. _RQLLogicalOperators:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   100
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   101
Logical operators
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   102
`````````````````
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   103
::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   104
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   105
     AND, OR, NOT, ','
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   106
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   107
',' is equivalent to 'AND' but with the smallest among the priority of logical
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   108
operators (see :ref:`RQLOperatorsPriority`).
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   109
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   110
.. _RQLMathematicalOperators:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   111
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   112
Mathematical operators
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   113
``````````````````````
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   114
::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   115
7738
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   116
+==========+=====================+===========+========+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   117
| Operator |    Description      | Example   | Result |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   118
+==========+=====================+===========+========+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   119
|  +       | addition            | 2 + 3     | 5      |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   120
+----------+---------------------+-----------+--------+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   121
|  -       | subtraction         | 2 - 3     | -1     |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   122
+----------+---------------------+-----------+--------+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   123
|  *       | multiplication      | 2 * 3     | 6      |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   124
+----------+---------------------+-----------+--------+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   125
|  /       | division            | 4 / 2     | 2      |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   126
+----------+---------------------+-----------+--------+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   127
|  %       | modulo (remainder)  | 5 % 4     | 1      |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   128
+----------+---------------------+-----------+--------+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   129
|  ^       | exponentiation      | 2.0 ^ 3.0 | 8      |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   130
+----------+---------------------+-----------+--------+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   131
|  &       | bitwise AND         | 91 & 15   | 11     |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   132
+----------+---------------------+-----------+--------+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   133
|  |       | bitwise OR          | 32 | 3    | 35     |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   134
+----------+---------------------+-----------+--------+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   135
|  #       | bitwise XOR         | 17 # 5    | 20     |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   136
+----------+---------------------+-----------+--------+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   137
|  ~       | bitwise NOT         | ~1        | -2     |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   138
+----------+---------------------+-----------+--------+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   139
|  <<      | bitwise shift left  | 1 << 4    | 16     |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   140
+----------+---------------------+-----------+--------+
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   141
|  >>      | bitwise shift right | 8 >> 2    | 2      |
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   142
+----------+---------------------+-----------+--------+
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   143
7738
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   144
  +, -, *, /
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   145
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   146
Notice integer division truncates results depending on the backend behaviour. For
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   147
instance, postgresql does.
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   148
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   149
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   150
.. _RQLComparisonOperators:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   151
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   152
Comparison operators
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   153
````````````````````
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   154
 ::
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   155
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   156
     =, !=, <, <=, >=, >, IN
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   157
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   158
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   159
The syntax to use comparison operators is:
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   160
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   161
    `VARIABLE attribute <operator> VALUE`
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   162
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   163
The `=` operator is the default operator and can be omitted, i.e. :
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   164
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   165
    `VARIABLE attribute = VALUE`
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   166
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   167
is equivalent to
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   168
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   169
    `VARIABLE attribute VALUE`
3686
d44b17016944 [doc] document rql operator ILIKE
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2175
diff changeset
   170
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   171
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   172
The operator `IN` provides a list of possible values: ::
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2043
diff changeset
   173
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   174
    Any X WHERE X name IN ('chauvat', 'fayolle', 'di mascio', 'thenault')
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   175
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   176
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   177
.. _RQLStringOperators:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   178
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   179
String operators
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   180
````````````````
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   181
::
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   182
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   183
  LIKE, ILIKE, ~=, REGEXP
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   184
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   185
The :keyword:`LIKE` string operator can be used with the special character `%` in
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   186
a string as wild-card: ::
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   187
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   188
     # match every entity whose name starts with 'Th'
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   189
     Any X WHERE X name ~= 'Th%'
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   190
     # match every entity whose name endswith 'lt'
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   191
     Any X WHERE X name LIKE '%lt'
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   192
     # match every entity whose name contains a 'l' and a 't'
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   193
     Any X WHERE X name LIKE '%l%t%'
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   194
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   195
:keyword:`ILIKE` is the case insensitive version of :keyword:`LIKE`. It's not
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   196
available on all backend (e.g. sqlite doesn't support it). If not available for
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   197
your backend, :keyword:`ILIKE` will behave like :keyword:`LIKE`.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   198
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   199
`~=` is a shortcut version of :keyword:`ILIKE`, or of :keyword:`LIKE` when the
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   200
former is not available on the back-end.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   201
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   202
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   203
The :keyword:`REGEXP` is an alternative to :keyword:`LIKE` that supports POSIX
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   204
regular expressions::
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   205
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   206
   # match entities whose title starts with a digit
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   207
   Any X WHERE X title REGEXP "^[0-9].*"
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   208
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   209
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   210
The underlying SQL operator used is back-end-dependent :
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   211
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   212
- the ``~`` operator is used for postgresql,
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   213
- the ``REGEXP`` operator for mysql and sqlite.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   214
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   215
Other back-ends are not supported yet.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   216
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   217
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   218
.. _RQLOperatorsPriority:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   219
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   220
Operators priority
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   221
``````````````````
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   222
7738
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   223
#. `(`, `)`
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   224
#. `^`, `<<`, `>>`
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   225
#. `*`, `/`, `%`, `&`
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   226
#. `+`, `-`, `|`, `#`
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   227
#. `NOT`
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   228
#. `AND`
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   229
#. `OR`
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   230
#. `,`
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   231
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   232
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   233
.. _RQLSearchQuery:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   234
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   235
Search Query
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   236
~~~~~~~~~~~~
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   237
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   238
Simplified grammar of search query: ::
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   239
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   240
   [ `DISTINCT`] `Any` V1 (, V2) \*
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   241
   [ `GROUPBY` V1 (, V2) \*] [ `ORDERBY` <orderterms>]
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   242
   [ `LIMIT` <value>] [ `OFFSET` <value>]
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   243
   [ `WHERE` <triplet restrictions>]
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   244
   [ `WITH` V1 (, V2)\* BEING (<query>)]
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   245
   [ `HAVING` <other restrictions>]
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   246
   [ `UNION` <query>]
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   247
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   248
Selection
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   249
`````````
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   250
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   251
The fist occuring clause is the selection of terms that should be in the result
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   252
set.  Terms may be variable, literals, function calls, arithmetic, etc. and each
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   253
term is separated by a comma.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   254
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   255
There will be as much column in the result set as term in this clause, respecting
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   256
order.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   257
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   258
Syntax for function call is somewhat intuitive, for instance: ::
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   259
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   260
    Any UPPER(N) WHERE P firstname N
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   261
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   262
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   263
Grouping and aggregating
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   264
````````````````````````
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   265
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   266
The :keyword:`GROUPBY` keyword is followed by a list of terms on which results
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   267
should be grouped. They are usually used with aggregate functions, responsible to
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   268
aggregate values for each group (see :ref:`RQLAggregateFunctions`).
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   269
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   270
For grouped queries, all selected variables must be either aggregated (i.e. used
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   271
by an aggregate function) or grouped (i.e. listed in the :keyword:`GROUPBY`
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   272
clause).
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   273
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   274
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   275
Sorting
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   276
```````
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   277
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   278
The :keyword:`ORDERBY` keyword if followed by the definition of the selection
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   279
order: variable or column number followed by sorting method (:keyword:`ASC`,
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   280
:keyword:`DESC`), :keyword:`ASC` being the default. If the sorting method is not
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   281
specified, then the sorting is ascendant (`ASC`).
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   282
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   283
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   284
Pagination
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   285
``````````
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   286
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   287
The :keyword:`LIMIT` and :keyword:`OFFSET` keywords may be respectively used to
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   288
limit the number of results and to tell from which result line to start (for
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   289
instance, use `LIMIT 20` to get the first 20 results, then `LIMIT 20 OFFSET 20`
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   290
to get the next 20.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   291
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   292
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   293
Restrictions
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   294
````````````
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   295
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   296
The :keyword:`WHERE` keyword introduce one of the "main" part of the query, where
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   297
you "define" variables and add some restrictions telling what you're interested
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   298
in.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   299
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   300
It's a list of triplets "subject relation object", e.g. `V1 relation
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   301
(V2 | <static value>)`. Triplets are separated using :ref:`RQLLogicalOperators`.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   302
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   303
.. Note:
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   304
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   305
  About the negation operator (:keyword:`NOT`):
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   306
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   307
  * "NOT X relation Y" is equivalent to "NOT EXISTS(X relation Y)"
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   308
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   309
  * `Any X WHERE NOT X owned_by U` means "entities that have no relation
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   310
    `owned_by`".
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   311
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   312
  * `Any X WHERE NOT X owned_by U, U login "syt"` means "the entity have no
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   313
     relation `owned_by` with the user syt". They may have a relation "owned_by"
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   314
     with another user.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   315
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   316
In this clause, you can also use :keyword:`EXISTS` when you want to know if some
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   317
expression is true and do not need the complete set of elements that make it
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   318
true. Testing for existence is much faster than fetching the complete set of
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   319
results, especially when you think about using `OR` against several expressions. For instance
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   320
if you want to retrieve versions which are in state "ready" or tagged by
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   321
"priority", you should write :
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   322
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   323
::
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   324
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   325
    Any X ORDERBY PN,N
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   326
    WHERE X num N, X version_of P, P name PN,
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   327
          EXISTS(X in_state S, S name "ready")
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   328
          OR EXISTS(T tags X, T name "priority")
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   329
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   330
not
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   331
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   332
::
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   333
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   334
    Any X ORDERBY PN,N
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   335
    WHERE X num N, X version_of P, P name PN,
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   336
          (X in_state S, S name "ready")
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   337
          OR (T tags X, T name "priority")
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   338
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   339
Both queries aren't at all equivalent :
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   340
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   341
* the former will retrieve all versions, then check for each one which are in the
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   342
  matching state of or tagged by the expected tag,
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   343
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   344
* the later will retrieve all versions, state and tags (cartesian product!),
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   345
  compute join and then exclude each row which are in the matching state of or
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   346
  tagged by the expected tag. This implies that : you won't get any result if the
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   347
  in_state or tag
7529
2fdc310be7cd [book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 7081
diff changeset
   348
2fdc310be7cd [book] add autoload section from code and fix sphinx warnings
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 7081
diff changeset
   349
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   350
You can also use the question mark (`?`) to mark optional relations which allow
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   351
you to select entities related **or not** to another. It is a similar concept
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   352
that the `Left outer join`_:
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   353
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   354
    the result of a left outer join (or simply left join) for table A and B
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   355
    always contains all records of the "left" table (A), even if the
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   356
    join-condition does not find any matching record in the "right" table (B).
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   357
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   358
You must use the `?` behind a variable to specify that the relation toward it
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   359
is optional. For instance:
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   360
7738
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   361
- Bugs of a project attached or not to a version ::
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   362
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   363
       Any X, V WHERE X concerns P, P eid 42, X corrected_in V?
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   364
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   365
  You will get a result set containing all the project's tickets, with either the
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   366
  version in which it's corrected or None for tickets not related to a version.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   367
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   368
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   369
- All cards and the project they document if any ::
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   370
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   371
       Any C, P WHERE C is Card, P? documented_by C
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   372
7738
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   373
Notice you may also use outer join:
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   374
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   375
- on the RHS of attribute relation, e.g. ::
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   376
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   377
       Any X WHERE X ref XR, Y name XR?
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   378
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   379
  so that Y is outer joined on X by ref/name attributes comparison
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   380
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   381
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   382
- on any side of an `HAVING` expression, e.g. ::
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   383
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   384
       Any X WHERE X creation_date XC, Y creation_date YC
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   385
       HAVING YEAR(XC)=YEAR(YC)?
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   386
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   387
  so that Y is outer joined on X by comparison of the year extracted from their
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   388
  creation date. ::
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   389
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   390
       Any X WHERE X creation_date XC, Y creation_date YC
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   391
       HAVING YEAR(XC)?=YEAR(YC)
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   392
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   393
  would outer join X on Y instead.
e0c86caf5c48 [book, rql] update rql langage chapter with new operators and outer join capabilities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7632
diff changeset
   394
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   395
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   396
Having restrictions
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   397
```````````````````
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   398
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   399
The :keyword:`HAVING` clause, as in SQL, may be used to restrict a query
6120
c000e41316ec [book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5924
diff changeset
   400
according to value returned by an aggregate function, e.g.::
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   401
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   402
    Any X GROUPBY X WHERE X relation Y HAVING COUNT(Y) > 10
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   403
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   404
It may however be used for something else: In the :keyword:`WHERE` clause, we are
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   405
limited to triplet expressions, so some things may not be expressed there. Let's
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   406
take an example : if you want to get people whose upper-cased first name equals to
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   407
another person upper-cased first name. There is no proper way to express this
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   408
using triplet, so you should use something like: ::
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   409
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   410
    Any X WHERE X firstname XFN, Y firstname YFN, NOT X identity Y HAVING UPPER(XFN) = UPPER(YFN)
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   411
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   412
Another example: imagine you want person born in 2000: ::
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   413
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   414
    Any X WHERE X birthday XB HAVING YEAR(XB) = 2000
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   415
6120
c000e41316ec [book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5924
diff changeset
   416
Notice that while we would like this to work without the HAVING clause, this
c000e41316ec [book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5924
diff changeset
   417
can't be currently be done because it introduces an ambiguity in RQL's grammar
c000e41316ec [book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5924
diff changeset
   418
that can't be handled by Yapps_, the parser's generator we're using.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   419
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   420
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   421
Sub-queries
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   422
```````````
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   423
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   424
The :keyword:`WITH` keyword introduce sub-queries clause. Each sub-query has the
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   425
form:
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   426
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   427
  V1(,V2) BEING (rql query)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   428
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   429
Variables at the left of the :keyword:`BEING` keyword defines into which
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   430
variables results from the sub-query will be mapped to into the outer query.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   431
Sub-queries are separated from each other using a comma.
6120
c000e41316ec [book] some more documentation and cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5924
diff changeset
   432
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   433
Let's say we want to retrieve for each project its number of versions and its
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   434
number of tickets. Due to the nature of relational algebra behind the scene, this
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   435
can't be achieved using a single query. You have to write something along the
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   436
line of: ::
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   437
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   438
  Any X, VC, TC WHERE X identity XX
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   439
  WITH X, VC BEING (Any X, COUNT(V) GROUPBY X WHERE V version_of X),
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   440
       XX, TC BEING (Any X, COUNT(T) GROUPBY X WHERE T ticket_of X)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   441
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   442
Notice that we can't reuse a same variable name as alias for two different
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   443
sub-queries, hence the usage of 'X' and 'XX' in this example, which are then
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   444
unified using the special `identity` relation (see :ref:`XXX`).
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   445
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   446
.. Warning:
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   447
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   448
  Sub-queries define a new variable scope, so even if a variable has the same name
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   449
  in the outer query and in the sub-query, they technically **aren't* the same
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   450
  variable. So ::
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   451
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   452
     Any W, REF WITH W, REF BEING
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   453
         (Any W, REF WHERE W is Workcase, W ref REF,
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   454
                           W concerned_by D, D name "Logilab")
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   455
  could be written:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   456
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   457
     Any W, REF WITH W, REF BEING
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   458
        (Any W1, REF1 WHERE W1 is Workcase, W1 ref REF1,
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   459
                            W1 concerned_by D, D name "Logilab")
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   460
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   461
  Also, when a variable is coming from a sub-query, you currently can't reference
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   462
  its attribute or inlined relations in the outer query, you've to fetch them in
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   463
  the sub-query. For instance, let's say we want to sort by project name in our
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   464
  first example, we would have to write ::
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   465
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   466
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   467
    Any X, VC, TC ORDERBY XN WHERE X identity XX
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   468
    WITH X, XN, VC BEING (Any X, COUNT(V) GROUPBY X,XN WHERE V version_of X, X name XN),
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   469
         XX, TC BEING (Any X, COUNT(T) GROUPBY X WHERE T ticket_of X)
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   470
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   471
  instead of ::
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2043
diff changeset
   472
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   473
    Any X, VC, TC ORDERBY XN WHERE X identity XX, X name XN,
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   474
    WITH X, XN, VC BEING (Any X, COUNT(V) GROUPBY X WHERE V version_of X),
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   475
         XX, TC BEING (Any X, COUNT(T) GROUPBY X WHERE T ticket_of X)
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   476
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   477
  which would result in a SQL execution error.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   478
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2043
diff changeset
   479
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   480
Union
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   481
`````
7081
6beb7f1e05fa [doc] complete description of EXISTS in rql/language.rst
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6324
diff changeset
   482
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   483
You may get a result set containing the concatenation of several queries using
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   484
the :keyword:`UNION`. The selection of each query should have the same number of
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   485
columns.
7081
6beb7f1e05fa [doc] complete description of EXISTS in rql/language.rst
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6324
diff changeset
   486
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   487
::
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2043
diff changeset
   488
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   489
    (Any X, XN WHERE X is Person, X surname XN) UNION (Any X,XN WHERE X is Company, X name XN)
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2043
diff changeset
   490
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2043
diff changeset
   491
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   492
.. _RQLFunctions:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   493
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   494
Available functions
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   495
~~~~~~~~~~~~~~~~~~~
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   496
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   497
Below is the list of aggregate and transformation functions that are supported
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   498
nativly by the framework. Notice that cubes may define additional functions.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   499
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   500
.. _RQLAggregateFunctions:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   501
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   502
Aggregate functions
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   503
```````````````````
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   504
+--------------------+----------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   505
| :func:`COUNT`      | return the number of rows                                |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   506
+--------------------+----------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   507
| :func:`MIN`        | return the minimum value                                 |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   508
+--------------------+----------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   509
| :func:`MAX`        | return the maximum value                                 |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   510
+--------------------+----------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   511
| :func:`AVG`        | return the average value                                 |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   512
+--------------------+----------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   513
| :func:`SUM`        | return the sum of values                                 |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   514
+--------------------+----------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   515
| :func:`COMMA_JOIN` | return each value separated by a comma (for string only) |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   516
+--------------------+----------------------------------------------------------+
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   517
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   518
All aggregate functions above take a single argument. Take care some aggregate
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   519
functions (e.g. :keyword:`MAX`, :keyword:`MIN`) may return `None` if there is no
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   520
result row.
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   521
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   522
.. _RQLStringFunctions:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   523
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   524
String transformation functions
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   525
```````````````````````````````
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   526
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   527
+-------------------------+-----------------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   528
| :func:`UPPER(String)`   | upper case the string                                           |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   529
+-------------------------+-----------------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   530
| :func:`LOWER(String)`   | lower case the string                                           |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   531
+-------------------------+-----------------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   532
| :func:`LENGTH(String)`  | return the length of the string                                 |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   533
+-------------------------+-----------------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   534
| :func:`SUBSTRING(       | extract from the string a string starting at given index and of |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   535
|  String, start, length)`| given length                                                    |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   536
+-------------------------+-----------------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   537
| :func:`LIMIT_SIZE(      | if the length of the string is greater than given max size,     |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   538
|  String, max size)`     | strip it and add ellipsis ("..."). The resulting string will    |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   539
|                         | hence have max size + 3 characters                              |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   540
+-------------------------+-----------------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   541
| :func:`TEXT_LIMIT_SIZE( | similar to the above, but allow to specify the MIME type of the |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   542
|  String, format,        | text contained by the string. Supported formats are text/html,  |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   543
|  max size)`             | text/xhtml and text/xml. All others will be considered as plain |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   544
|                         | text. For non plain text format, sgml tags will be first removed|
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   545
|                         | before limiting the string.                                     |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   546
+-------------------------+-----------------------------------------------------------------+
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   547
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   548
.. _RQLDateFunctions:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   549
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   550
Date extraction functions
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   551
`````````````````````````
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   552
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   553
+--------------------------+----------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   554
| :func:`YEAR(Date)`       | return the year of a date or datetime  |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   555
+--------------------------+----------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   556
| :func:`MONTH(Date)`      | return the year of a date or datetime  |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   557
+--------------------------+----------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   558
| :func:`DAY(Date)`        | return the year of a date or datetime  |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   559
+--------------------------+----------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   560
| :func:`HOUR(Datetime)`   | return the year of a datetime          |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   561
+--------------------------+----------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   562
| :func:`MINUTE(Datetime)` | return the year of a datetime          |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   563
+--------------------------+----------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   564
| :func:`SECOND(Datetime)` | return the year of a datetime          |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   565
+--------------------------+----------------------------------------+
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   566
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   567
.. _RQLOtherFunctions:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   568
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   569
Other functions
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   570
```````````````
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   571
+-----------------------+--------------------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   572
| :func:`ABS(num)`      |  return the absolute value of a number                             |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   573
+-----------------------+--------------------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   574
| :func:`RANDOM()`      | return a pseudo-random value from 0.0 to 1.0                       |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   575
+-----------------------+--------------------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   576
| :func:`FSPATH(X)`     | expect X to be an attribute whose value is stored in a             |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   577
|                       | :class:`BFSStorage` and return its path on the file system         |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   578
+-----------------------+--------------------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   579
| :func:`FTKIRANK(X)`   | expect X to be an entity used in a has_text relation, and return a |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   580
|                       | number corresponding to the rank order of each resulting entity    |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   581
+-----------------------+--------------------------------------------------------------------+
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   582
| :func:`CAST(Type, X)` | expect X to be an attribute and return it casted into the given    |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   583
|                       | final type                                                         |
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   584
+-----------------------+--------------------------------------------------------------------+
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2043
diff changeset
   585
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   586
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   587
.. _RQLExamples:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   588
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   589
Examples
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   590
~~~~~~~~
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   591
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   592
- *Search for the object of identifier 53*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   593
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   594
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   595
        Any WHERE X
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   596
        X eid 53
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   597
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   598
- *Search material such as comics, owned by syt and available*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   599
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   600
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   601
        Any X WHERE X is Document
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   602
        X occurence_of F, F class C, C name 'Comics'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   603
        X owned_by U, U login 'syt'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   604
        X available TRUE
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   605
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   606
- *Looking for people working for eurocopter interested in training*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   607
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   608
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   609
        Any P WHERE
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   610
        P is Person, P work_for S, S name 'Eurocopter'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   611
        P interested_by T, T name 'training'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   612
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   613
- *Search note less than 10 days old written by jphc or ocy*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   614
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   615
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   616
        Any N WHERE
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   617
        N is Note, N written_on D, D day> (today -10),
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   618
        N written_by P, P name 'jphc' or P name 'ocy'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   619
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   620
- *Looking for people interested in training or living in Paris*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   621
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   622
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   623
        Any P WHERE
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   624
        P is Person, (P interested_by T, T name 'training') OR
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   625
        (P city 'Paris')
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   626
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   627
- *The surname and firstname of all people*
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   628
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   629
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   630
        Any N, P WHERE
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   631
        X is Person, X name N, X firstname P
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   632
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   633
  Note that the selection of several entities generally force
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   634
  the use of "Any" because the type specification applies otherwise
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   635
  to all the selected variables. We could write here
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   636
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   637
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   638
        String N, P WHERE
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   639
        X is Person, X name N, X first_name P
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   640
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   641
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   642
  Note: You can not specify several types with * ... where X is FirstType or X is SecondType*.
2043
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1714
diff changeset
   643
  To specify several types explicitly, you have to do
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   644
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   645
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   646
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   647
        Any X where X is in (FirstType, SecondType)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   648
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   649
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   650
.. _RQLInsertQuery:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   651
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   652
Insertion query
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   653
~~~~~~~~~~~~~~~
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   654
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   655
    `INSERT` <entity type> V1 (, <entity type> V2) \ * `:` <assignments>
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   656
    [ `WHERE` <restriction>]
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   657
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   658
:assignments:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   659
   list of relations to assign in the form `V1 relationship V2 | <static value>`
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   660
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   661
The restriction can define variables used in assignments.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   662
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2043
diff changeset
   663
Caution, if a restriction is specified, the insertion is done for
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   664
*each line result returned by the restriction*.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   665
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   666
- *Insert a new person named 'foo'*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   667
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   668
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   669
        INSERT Person X: X name 'foo'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   670
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   671
- *Insert a new person named 'foo', another called 'nice' and a 'friend' relation
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   672
  between them*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   673
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   674
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   675
        INSERT Person X, Person Y: X name 'foo', Y name 'nice', X friend Y
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   676
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2043
diff changeset
   677
- *Insert a new person named 'foo' and a 'friend' relation with an existing
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   678
  person called 'nice'*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   679
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   680
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   681
        INSERT Person X: X name 'foo', X friend  Y WHERE name 'nice'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   682
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   683
.. _RQLSetQuery:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   684
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   685
Update and relation creation queries
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   686
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   687
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   688
    `SET` <assignements>
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   689
    [ `WHERE` <restriction>]
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   690
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   691
Caution, if a restriction is specified, the update is done *for
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   692
each result line returned by the restriction*.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   693
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   694
- *Renaming of the person named 'foo' to 'bar' with the first name changed*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   695
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   696
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   697
        SET X name 'bar', X firstname 'original' WHERE X is Person, X name 'foo'
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   698
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2043
diff changeset
   699
- *Insert a relation of type 'know' between objects linked by
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   700
  the relation of type 'friend'*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   701
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   702
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   703
        SET X know Y  WHERE X friend Y
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   704
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   705
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   706
.. _RQLDeleteQuery:
7632
3c9dfc6e820b [book] fix some rest/sphinx errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7578
diff changeset
   707
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   708
Deletion query
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   709
~~~~~~~~~~~~~~
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   710
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   711
    `DELETE` (<entity type> V) | (V1 relation v2 ),...
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   712
    [ `WHERE` <restriction>]
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   713
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   714
Caution, if a restriction is specified, the deletion is made *for
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   715
each line result returned by the restriction*.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   716
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   717
- *Deletion of the person named 'foo'*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   718
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   719
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   720
        DELETE Person X WHERE X name 'foo'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   721
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   722
- *Removal of all relations of type 'friend' from the person named 'foo'*
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   723
  ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   724
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   725
        DELETE X friend Y WHERE X is Person, X name 'foo'
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   726
5924
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   727
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   728
.. _Yapps: http://theory.stanford.edu/~amitp/yapps/
b218df942dd4 [book] update rql documentation and some erroneous/deprecated examples
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5393
diff changeset
   729
.. _Left outer join: http://en.wikipedia.org/wiki/Join_(SQL)#Left_outer_join
7578
49be8619b745 [book] rewrite / complete the RQL language chapter
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7529
diff changeset
   730