doc/book/en/C040-rql.en.txt
author Nicolas Chauvat <nicolas.chauvat@logilab.fr>
Sat, 22 Nov 2008 23:59:42 +0100
changeset 127 ae611743f5c6
parent 115 doc/book/en/16-00-rql.en.txt@4b66ad23fbd1
child 209 38a9c240ac64
permissions -rw-r--r--
[doc] divided book in parts
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     1
.. -*- coding: utf-8 -*-
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     2
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
     3
RQL language (Relation Query Language)
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
     4
======================================
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
     5
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
     6
XXX see also RQL documentation in source rql/doc.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
     7
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
     8
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
     9
Introduction
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    10
------------
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    11
* RQL language focuses on browsing relations.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    12
* Attributes are considered as particular relations.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    13
* RQL is inspired from SQL but is a high level language.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    14
* A good knowledge of Erudi's schemas defining the application is required.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    15
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    16
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    17
Types of requests
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    18
-----------------
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    19
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    20
Search (`Any`)
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    21
  query the repository to extract entities and/or attributes.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    22
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    23
Insertion (`INSERT`)
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    24
  insert new entities in the database.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    25
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    26
Updates of entities, creation of relations (`SET`)
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    27
  update existing entities in the database, or create relations between existing
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    28
  entities
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    29
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    30
Deletion of entities or relations (`DELETE`)
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    31
  delete existing entities and relations from the database.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    32
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    33
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    34
Variables and typing
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    35
--------------------
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    36
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    37
Entities and values to browse and/or select are set in the query through *variables*
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    38
which should be written in capital letters.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    39
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    40
The possible types for each variable can be deducted from the schema depending on
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    41
the conditions expressed in the query.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    42
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    43
You can force the possible types for a variable thanks to the special relation `is`.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    44
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    45
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    46
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    47
Built-in types
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    48
--------------
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    49
* `String` (literal: between double or single quotes).
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    50
* `Int`, `Float` (separator is '.').
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    51
* `Date`, `Datetime`, `Time` (literal: pattern YYYY/MM/DD[ hh:mm] or keywords
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    52
  `TODAY` and `NOW`).
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    53
* `Boolean` (keywords `TRUE` et `FALSE`).
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    54
* keyword `NULL`.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    55
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    56
Operators
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    57
----------
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    58
* Logical operators: `AND`, `OR`, `,`.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    59
* Mathematical operators: `+`, `-`, `*`, `/`.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    60
* Comparison operators: `=`, `<`, `<=`, `>=`, `>`, `~=`, `LIKE`, `IN`.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    61
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    62
  * The operator `=` is the default operator.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    63
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    64
  * The operator `LIKE` / `~=` allows the use of the character `%` in a string
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    65
    to indicate that the string should start/end with a prefix/suffix::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    66
    
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    67
      Any X WHERE X nom ~= 'Th%'
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    68
      Any X WHERE X nom LIKE '%lt'
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    69
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    70
  * The operator `IN` allows to provide a list of possible values::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    71
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    72
      Any X WHERE X nom IN ('chauvat', 'fayolle', 'di mascio', 'thenault')
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    73
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    74
Search query
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    75
------------
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    76
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    77
  [`DISTINCT`] <entity type> V1(, V2)\*
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    78
  [`GROUPBY` V1(, V2)\*]  [`ORDERBY` <orderterms>]
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    79
  [`WHERE` <condition>] 
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    80
  [`LIMIT` <value>] [`OFFSET` <value>]
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    81
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    82
:entity type:
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    83
  Type of the selected variable
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    84
  Special type `Any` is equivalent to not specify a type
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    85
:condition:
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    86
  list of relations to browse following the pattern 
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    87
    `V1 relation V2|<static value>`
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    88
:orderterms:
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    89
  Setting of the selection order : variable or column number followed by the
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    90
  sorting method (`ASC`, `DESC`), ASC being the default value.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    91
:note  for grouped queries:
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    92
  For grouped queries (e.g. using function `GROUPBY`), all the selected 
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    93
  variables must be grouped or aggregated.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    94
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    95
Examples - search
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    96
~~~~~~~~~~~~~~~~~
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    97
::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    98
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    99
      Any X WHERE X eid 53
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   100
      Personne X
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   101
      Personne X WHERE X travaille_pour S, S nom "logilab"
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   102
      Any E,COUNT(X) GROUPBY E ORDERBY EN WHERE X is E, E name EN 
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   103
      Any E,COUNT(X) GROUPBY E ORDERBY 2 WHERE X is E 
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   104
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   105
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   106
Advanced features
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   107
~~~~~~~~~~~~~~~~~
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   108
* Aggregate functions: `COUNT`, `MIN`, `MAX`, `SUM`.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   109
* String functions:`UPPER`, `LOWER`.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   110
* Optional relations:
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   111
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   112
  * They allow to select entities related to others or not.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   113
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   114
  * You should use `?` behind the variable to specify the relation to itself is
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   115
    optional.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   116
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   117
    - Project anomalies related to a version or not::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   118
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   119
        Any X,V WHERE X concerns P, P eid 42, X corrected_in V?
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   120
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   121
    - All the cards and the project they document otherwise ::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   122
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   123
        Any C,P WHERE C is Card, P? documented_by C
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   124
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   125
Negation
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   126
~~~~~~~~
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   127
* A query such as `Document X WHERE NOT X owned_by U` is equivalent to 
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   128
  "the documents which do not have relation `owned_by`".
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   129
* Whereas the query `Document X WHERE NOT X owned_by U, U login "syt"`
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   130
  is equivalent to "the documents which do not have relation `owned_by`
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   131
  with the user syt". They could have a relation with other users.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   132
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   133
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   134
Identity
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   135
~~~~~~~~
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   136
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   137
We could use the special relation `identity` in a query in order to add a
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   138
condition of identity between two variables. This is equivalent to ``is``
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   139
in Python.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   140
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   141
  Any A WHERE A comments B, A identity B
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   142
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   143
returns the set of objects which comment themselves. The relation `identity`
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   144
is very usefull while defining security rules with `RQLExpressions`.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   145
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   146
Insertion queries
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   147
-----------------
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   148
   `INSERT` <entity type> V1(, <entity type> V2)\* `:` <assignments>
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   149
   [`WHERE` <condition>] 
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   150
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   151
:assignments:
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   152
  list of relations to assign such as `V1 relation V2|<static value>`
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   153
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   154
The condition allow to define the variables we would use in assignments.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   155
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   156
Be careful, if a condition is specified, the insertion is done *for each result
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   157
returned by the condition*.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   158
 
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   159
Examples - insertion
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   160
~~~~~~~~~~~~~~~~~~~~~
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   161
* Insertion of a new person named 'bidule'::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   162
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   163
       INSERT Person X: X name 'bidule'
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   164
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   165
* Insertion of a new person named 'bidule', another named
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   166
  'chouette' and a relation 'friend' between them::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   167
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   168
       INSERT Person X, Person Y: X name 'bidule', Y name 'chouette', X friend Y
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   169
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   170
* Insertion of a new person named 'bidule' and a relation 'friend'with an 
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   171
  existing person 'chouette'::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   172
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   173
       INSERT Person X: X name 'bidule', X friend Y WHERE Y name 'chouette'
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   174
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   175
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   176
Update queries
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   177
--------------
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   178
   `SET` <assignments>
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   179
   [`WHERE` <condition>] 
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   180
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   181
Be careful, if a condition is specified, the update is done *for each result
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   182
returned by the condition*.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   183
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   184
Examples - update 
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   185
~~~~~~~~~~~~~~~~~
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   186
* Renaming of the person named 'bidule' to 'toto', with change on the first name::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   187
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   188
       SET X name 'toto', X firstname 'original' WHERE X is 'Person', X name 'bidule'
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   189
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   190
* Insertion of a relation of type 'know' between two objects linked with the relation
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   191
  of type 'friend' ::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   192
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   193
       SET X know Y WHERE X friend Y
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   194
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   195
Deletion queries
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   196
----------------
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   197
   `DELETE` (<entity type> V) | (V1 relation v2),...
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   198
   [`WHERE` <condition>] 
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   199
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   200
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   201
Be careful, if a condition is specified, the deletion is done *for each result
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   202
returned by the condition*.
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   203
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   204
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   205
Examples
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   206
~~~~~~~~
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   207
* Deletion of the person named 'toto'::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   208
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   209
       DELETE Person X WHERE X name 'toto'
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   210
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   211
* Deletion of all the relations of type 'friend' linked to the person named 
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   212
  'toto'::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   213
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   214
       DELETE X friend Y WHERE X is 'Person', X name 'toto'
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   215
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   216