doc/book/en/C040-rql.en.txt
author Nicolas Chauvat <nicolas.chauvat@logilab.fr>
Mon, 22 Dec 2008 17:02:01 +0100
changeset 255 5d2804b9a28c
parent 209 38a9c240ac64
child 274 893353d66f86
permissions -rw-r--r--
[doc] add internal links from book abstract
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
255
5d2804b9a28c [doc] add internal links from book abstract
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 209
diff changeset
     3
.. _RQL:
5d2804b9a28c [doc] add internal links from book abstract
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 209
diff changeset
     4
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
     5
======================================
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
     6
RQL language (Relation Query Language)
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
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
     9
Introduction
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    10
============
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    11
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    12
Goals RQL
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    13
---------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    14
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    15
The goal is to have a language emphasizing the way of browsing
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    16
relations. As such, attributes will be regarded as cases of
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    17
special relations (in terms of implementation, the user
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    18
language not to see virtually no difference between an attribute and a
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    19
relation).
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    20
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    21
RQL is inspired by SQL but is the highest level. A knowledge of the 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    22
`CubicWeb` schema defining the application is necessary.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    23
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    24
Comparison with existing languages
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    25
----------------------------------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    26
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    27
SQL
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    28
```
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    29
RQL builds on the features of SQL but is at a higher level
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    30
(the current implementation of RQL generates SQL). For that it is limited
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    31
to the way of browsing relations and introduces variables. 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    32
The user does not need to know the model underlying SQL, but the `CubicWeb` 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    33
scheam defining the application.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    34
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    35
Versa
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    36
`````
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    37
Should I look in more detail, but here is already some ideas for
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    38
the moment ... Versa_ is the language most similar to what we wanted
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    39
to do, but the model underlying data being RDF, there is some
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    40
number of things such as namespaces or handling of the RDF types which 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    41
does not interest us. On the functionality level, Versa_ is very comprehensive
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    42
including through many functions of conversion and basic types manipulation,
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    43
which may need to be guided at one time or another. 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    44
Finally, the syntax is a little esoteric.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    45
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    46
See also
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    47
``````````
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    48
RDFQL_
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    49
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    50
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    51
The different types of queries
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    52
------------------------------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    53
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    54
Search ( `Any`)
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    55
   This type of query can extract entities and attributes of entities.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    56
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    57
Inserting entities ( `INSERT`)
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    58
   This type of query is used to insert new entities in the database. It
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    59
   will also create direct relationships entities newly created.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    60
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    61
Update entities, relations creation( `SET`)
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    62
   This type of query updates existing entities in the database,
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    63
   or create relations between existing entities.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    64
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    65
Deletion of entities or relationship ( `DELETE`)
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    66
   This type of query allows for the removal of entities and relations existing
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    67
   in the database.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    68
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    69
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    70
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    71
Examples
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    72
========
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    73
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    74
(see the tutorial: ref: `tutorielRQL` for more examples)
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    75
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    76
Search Query
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
    77
------------
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    78
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    79
   [ `DISTINCT`] <entity type> V1 (V2) \ *
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    80
   [ `GROUPBY` V1 (V2) \*] [ `ORDERBY` <orderterms>]
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    81
   [ `WHERE` <restriction>]
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    82
   [ `LIMIT` <value>] [ `OFFSET` <value>]
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    83
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    84
:entity type:
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    85
   Type of selected variables.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    86
   The special type `Any` is equivalent to not specify a type.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    87
:restriction:
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    88
   list of relations to go through whic follow the pattern
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    89
     `V1 relation V2 | <static value>`
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    90
:orderterms:
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    91
   Definition of the selection order: variable or column number followed by
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    92
   sorting method ( `ASC`, `DESC`), ASC is the default.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    93
:note for grouped queries:
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    94
   For grouped queries (e.g., a clause `GROUPBY`), all
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    95
   selected variables must be aggregated or grouped.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    96
115
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
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    99
- *Search for the object of identifier 53*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   100
   ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   101
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   102
        Any WHERE X
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   103
        X eid 53
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   104
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   105
- *Search material such as comics, owned by syt and available*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   106
   ::
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   107
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   108
        WHERE X Document
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   109
        X occurence_of F, F class C, C name 'Comics'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   110
        X owned_by U, U login 'syt'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   111
        X available true
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   112
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   113
- *Looking for people working for eurocopter interested in training*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   114
   ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   115
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   116
        Person P WHERE
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   117
        P work_for P, S name 'Eurocopter'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   118
        P interested_by T, T name 'training'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   119
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   120
- *Search note less than 10 days old written by jphc or ocy*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   121
   ::
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   122
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   123
        Note N WHERE
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   124
        N written_on D, D day> (today -10),
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   125
        N written_by P, P name 'jphc' or P name 'ocy'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   126
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   127
- *Looking for people interested in training or living in Paris*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   128
   ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   129
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   130
        Person P WHERE
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   131
        (P interested_by T, T name 'training') or
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   132
        (P city 'Paris')
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   133
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   134
- *The name and surname of all people*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   135
   ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   136
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   137
        Any N, P WHERE
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   138
        X is Person, X name N, X first_name P
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   139
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   140
   Note that the selection of several entities generally force
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   141
   the use of "Any" because the type specification applies otherwise
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   142
   to all the selected variables. We could write here
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   143
   ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   144
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   145
        String N, P WHERE
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   146
        X is Person, X name N, X first_name P
115
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
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   149
Insertion query
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   150
---------------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   151
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   152
    `INSERT` <entity type> V1 (, <entity type> V2) \ * `:` <assignments>
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   153
    [ `WHERE` <restriction>]
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   154
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   155
: assignments:
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   156
   list of relations to assign in the form `V1 relationship V2 | <static value>`
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   157
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   158
The restriction can define variables used in assignments.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   159
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   160
Caution, if a restriction is specified, the insertion is done for 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   161
*each line results returned by the restriction*.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   162
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   163
- *Insert a new person named 'foo'*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   164
   ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   165
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   166
        INSERT Person X: X name 'widget'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   167
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   168
- *Insert a new person named 'foo', another called 'nice' and a 'friend' relation
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   169
  between them*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   170
  ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   171
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   172
        INSERT Person X, Person Y: X name 'foo', Y name 'nice', X friend Y
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   173
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   174
- *Insert a new person named 'foo' and a 'friend' relation with an existing 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   175
  person called 'nice'*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   176
  ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   177
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   178
        INSERT Person X: X name 'foo', X friend  Y WHERE name 'nice'
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   179
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   180
Update and relation creation queries
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   181
------------------------------------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   182
    `SET` <assignements>
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   183
    [ `WHERE` <restriction>]
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   184
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   185
Caution, if a restriction is specified, the update is done *for
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   186
each line results returned by the restriction*.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   187
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   188
- *Renaming of the person named 'foo' to 'bar' with the first name changed*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   189
  ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   190
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   191
        SET X name 'bar', X first_name 'original' where X is Person X name 'foo'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   192
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   193
- *Insert a relation of type 'know' between objects linked by 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   194
  the relation of type 'friend'*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   195
  ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   196
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   197
        SET X know Y  WHERE X friend Y
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   198
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   199
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   200
Deletion query
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   201
--------------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   202
    `DELETE` (<entity type> V) | (V1 relation v2 ),...
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   203
    [ `WHERE` <restriction>]
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   204
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   205
Caution, if a restriction is specified, the deletion is made *for
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   206
each line results returned by the restriction*.
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   207
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   208
- *Deletion of the person named 'foo'*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   209
  ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   210
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   211
        DELETE Person X WHERE X name 'foo'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   212
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   213
- *Removal of all relations of type 'friend' from the person named 'foo'*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   214
  ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   215
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   216
        DELETE X friend Y WHERE X is Person, X name 'foo'
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   217
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   218
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   219
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   220
Language definition
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   221
===================
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   222
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   223
Reserved keywords
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   224
-----------------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   225
The keywords are not case sensitive.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   226
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   227
::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   228
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   229
     DISTINCT, INSERT, SET, DELETE,
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   230
     WHERE, AND, OR, NOT
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   231
     IN, LIKE,
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   232
     TRUE, FALSE, NULL, TODAY, NOW
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   233
     GROUPBY, ORDERBY, ASC, DESC
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   234
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   235
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   236
Variables and Typing
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   237
--------------------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   238
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   239
With RQL, we do not distinguish between entities and attributes. The
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   240
value of an attribute is considered an entity of a particular type (see
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   241
below), linked to one (real) entity by a relation called the name of
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   242
the attribute.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   243
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   244
Entities and values to browse and/or select are represented in
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   245
the query by *variables* that must be written in capital letters.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   246
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   247
There is a special type **Any**, referring to a non specific type.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   248
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   249
We can restrict the possible types for a variable using the
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   250
special relation **is**.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   251
The possible type(s) for each variable is derived from the schema
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   252
according to the constraints expressed above and thanks to the relations between
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   253
each variable.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   254
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   255
Built-in types
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   256
``````````````
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   257
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   258
The base types supported are string (between double or single quotes),
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   259
integers or floats (the separator is the'.'), dates and
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   260
boolean. We expect to receive a schema in which types String,
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   261
Int, Float, Date and Boolean are defined.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   262
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   263
* `String` (literal: between double or single quotes).
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   264
* `Int`, `Float` (separator being'.').
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   265
* `Date`, `Datetime`, `Time` (literal: string YYYY/MM/DD [hh:mm] or keywords
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   266
   `TODAY` and `NOW`).
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   267
* `Boolean` (keywords `TRUE` and `FALSE`).
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   268
* `Keyword` NULL.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   269
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   270
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   271
Operators
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   272
---------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   273
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   274
Logical Operators
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   275
```````````````````
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   276
::
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   277
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   278
     AND, OR, ','
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   279
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   280
',' is equivalent to 'AND' but with the smallest among the priority
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   281
of logical operators (see :ref:`PriorityOperators`).
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   282
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   283
Mathematical Operators
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   284
``````````````````````
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   285
::
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   286
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   287
     +, -, *, /
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   288
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   289
Comparison operators
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   290
````````````````````
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   291
::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   292
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   293
     =, <, <=, >=, > = ~, IN, LIKE
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   294
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   295
* The operator `=` is the default operator.
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   296
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   297
* The operator `LIKE` equivalent to `~=` can be used with the
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   298
  special character `%` in a string to indicate that the chain 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   299
  must start or finish by a prefix/suffix:
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   300
  ::
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   301
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   302
     Any X WHERE X name =~ 'Th%'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   303
     Any X WHERE X name LIKE '%lt'
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   304
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   305
* The operator `IN` provides a list of possible values:
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   306
  ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   307
  
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   308
    Any X WHERE X name IN ( 'chauvat', 'fayolle', 'di mascio', 'thenault')
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   309
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   310
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   311
XXX nico: A trick <> 'bar' would not it be more convenient than NOT A
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   312
trick 'bar'?
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   313
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   314
.. _PriorityOperators:
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   315
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   316
Operators priority
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   317
``````````````````
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   318
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   319
1. '*', '/'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   320
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   321
2. '+', '-'
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   322
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   323
3. 'and'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   324
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   325
4. 'or'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   326
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   327
5. ','
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   328
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   329
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   330
Advanced Features
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   331
-----------------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   332
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   333
Functions aggregates
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   334
````````````````````
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   335
::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   336
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   337
     COUNT, MIN, MAX, AVG, SUM
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   338
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   339
Functions on string
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   340
```````````````````
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   341
::
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   342
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   343
     UPPER, LOWER
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   344
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   345
Optional relations
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   346
``````````````````
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   347
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   348
* They allow you to select entities related or not to another.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   349
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   350
* You must use the `?` behind the variable to specify that the relation
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   351
  toward it is optional:
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   352
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   353
   - Anomalies of a project attached or not to a version ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   354
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   355
       Any X, V WHERE X concerns P, P eid 42, X corrected_in V?
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   356
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   357
   - All cards and the project they document if necessary ::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   358
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   359
       Any C, P WHERE C is Card, P? documented_by C
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   360
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   361
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   362
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   363
BNF grammar
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   364
-----------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   365
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   366
The terminal elements are in capital letters, non-terminal in lowercase.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   367
The value of the terminal elements (between quotes) is a Python regular
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   368
expression.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   369
::
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   370
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   371
     statement:: = (select | delete | insert | update) ';'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   372
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   373
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   374
     # select specific rules
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   375
     select      ::= 'DISTINCT'? E_TYPE selected_terms restriction? group? sort?
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   376
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   377
     selected_terms ::= expression ( ',' expression)*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   378
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   379
     group       ::= 'GROUPBY' VARIABLE ( ',' VARIABLE)*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   380
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   381
     sort        ::= 'ORDERBY' sort_term ( ',' sort_term)*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   382
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   383
     sort_term   ::=  VARIABLE sort_method =?
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   384
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   385
     sort_method ::= 'ASC' | 'DESC'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   386
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   387
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   388
     # delete specific rules
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   389
     delete ::= 'DELETE' (variables_declaration | relations_declaration) restriction?
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   390
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   391
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   392
     # insert specific rules
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   393
     insert ::= 'INSERT' variables_declaration ( ':' relations_declaration)? restriction?
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   394
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   395
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   396
     # update specific rules
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   397
     update ::= 'SET' relations_declaration restriction
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   398
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   399
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   400
     # common rules
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   401
     variables_declaration ::= E_TYPE VARIABLE (',' E_TYPE VARIABLE)*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   402
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   403
     relations_declaration ::= simple_relation (',' simple_relation)*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   404
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   405
     simple_relation ::= VARIABLE R_TYPE expression
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   406
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   407
     restriction ::= 'WHERE' relations
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   408
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   409
     relations   ::= relation (LOGIC_OP relation)*
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   410
                   | '(' relations')'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   411
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   412
     relation    ::= 'NOT'? VARIABLE R_TYPE COMP_OP? expression
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   413
                   | 'NOT'? R_TYPE VARIABLE 'IN' '(' expression (',' expression)* ')'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   414
                   
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   415
     expression  ::= var_or_func_or_const (MATH_OP var_or_func_or_const) *
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   416
                   | '(' expression ')'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   417
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   418
     var_or_func_or_const ::= VARIABLE | function | constant
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   419
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   420
     function    ::= FUNCTION '(' expression ( ',' expression) * ')'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   421
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   422
     constant    ::= KEYWORD | STRING | FLOAT | INT
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   423
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   424
     # tokens
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   425
     LOGIC_OP ::= ',' | 'GOLD' | 'AND'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   426
     MATH_OP  ::= '+' | '-' | '/' | '*'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   427
     COMP_OP  ::= '>' | '>=' | '=' | '<=' | '<' | '~=' | 'LIKE'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   428
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   429
     FUNCTION ::= 'MIN' | 'MAX' | 'SUM' | 'AVG' | 'COUNT' | 'upper' | 'LOWER'
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   430
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   431
     VARIABLE ::= '[A-Z][A-Z0-9]*'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   432
     E_TYPE   ::= '[A-Z]\w*'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   433
     R_TYPE   ::= '[a-z_]+'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   434
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   435
     KEYWORD  ::= 'TRUE' | 'FALSE' | 'NULL' | 'TODAY' | 'NOW'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   436
     STRING   ::= "'([^'\]|\\.)*'" |'"([^\"]|\\.)*\"'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   437
     FLOAT    ::= '\d+\.\d*'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   438
     INT      ::= '\d+'
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   439
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   440
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   441
Remarks
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   442
-------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   443
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   444
Sorting and groups
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   445
``````````````````
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   446
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   447
- For grouped queries (e.g. with a GROUPBY clause), all
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   448
  selected variables should be grouped.
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   449
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   450
- To group and/or sort by attributes, we can do: "X,L user U, U
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   451
  login L GROUPBY L, X ORDERBY L"
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   452
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   453
- If the sorting method (SORT_METHOD) is not specified, then the sorting is
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   454
  ascendant.
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   455
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   456
Negation
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   457
````````
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   458
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   459
* A query such as `Document X WHERE NOT X owned_by U` means "the
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   460
  documents have no relation `owned_by`".
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   461
* But the query `Document X WHERE NOT X owned_by U, U login "syt"`
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   462
  means "the documents have no relation `owned_by` with the user
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   463
  syt". They may have a relation "owned_by" with another user.
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   464
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   465
Identity
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   466
````````
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   467
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   468
You can use the special relation `identity` in a query to 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   469
add an identity constraint between two variables. This is equivalent
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   470
to ``is`` in python::
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   471
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   472
   Any A WHERE A comments B, A identity B
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   473
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   474
return all objects that comment themselves. The relation
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   475
`identity` is especially useful when defining the rules for securities
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   476
with `RQLExpressions`.
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   477
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   478
Implementation
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   479
==============
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   480
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   481
Internal representation (syntactic tree)
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   482
----------------------------------------
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   483
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   484
The tree research does not contain the selected variables 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   485
(e.g. there is only what follows "WHERE").
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   486
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   487
The insertion tree does not contain the variables inserted or relations
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   488
defined on these variables (e.g. there is only what follows "WHERE").
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   489
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   490
The removal tree does not contain the deleted variables and relations
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   491
(e.g. there is only what follows the "WHERE").
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   492
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   493
The update tree does not contain the variables and relations updated
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   494
(e.g. there is only what follows the "WHERE").
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   495
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   496
::
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   497
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   498
     Select         ((Relationship | And | Gold)?, Group?, Sort?)
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   499
     Insert         (Relations | And | Gold)?
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   500
     Delete         (Relationship | And | Gold)?
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   501
     Update         (Relations | And | Gold)?
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   502
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   503
     And            ((Relationship | And | Gold), (Relationship | And | Gold))
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   504
     Or             ((Relationship | And | Gold), (Relationship | And | Gold))
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   505
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   506
     Relationship   ((VariableRef, Comparison))
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   507
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   508
     Comparison     ((Function | MathExpression | Keyword | Constant | VariableRef) +)
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   509
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   510
     Function       (())
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   511
     MathExpression ((MathExpression | Keyword | Constant | VariableRef), (MathExpression | Keyword | Constant | VariableRef))
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   512
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   513
     Group          (VariableRef +)
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   514
     Sort           (SortTerm +)
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   515
     SortTerm       (VariableRef +)
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   516
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   517
     VariableRef    ()
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   518
     Variable       ()
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   519
     Keyword        ()
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   520
     Constant       ()
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   521
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   522
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   523
Remarks
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   524
-------
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   525
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   526
- The current implementation does not support linking two relations of type
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   527
  'is' with a OR. I do not think that the negation is  supported on this type 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   528
  of relation (XXX FIXME to be confirmed).
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   529
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   530
- Relations defining the variables must be left to those using them. 
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   531
  For example::
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   532
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   533
     Point P where P abs X, P ord Y, P value X+Y
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   534
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   535
   is valid, but::
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   536
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   537
     Point P where P abs X, P value X+Y, P ord Y
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   538
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   539
   is not.
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   540
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   541
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   542
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   543
Conclusion
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   544
==========
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   545
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   546
Limitations
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   547
-----------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   548
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   549
It lacks at the moment:
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   550
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   551
- COALESCE
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   552
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   553
- restrictions on groups (HAVING)
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   554
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   555
and certainly other things ...
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   556
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   557
A disadvantage is that to use this language we must know the
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   558
format used (with real relation names and entities, not those viewing
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   559
in the user interface). On the other hand, we can not really bypass
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   560
that, and it is the job of a user interface to hide the RQL.
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   561
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   562
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   563
Topics
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   564
------
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   565
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   566
It would be convenient to express the schema matching
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   567
relations (non-recursive rules)::
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   568
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   569
     Document class Type <-> Document occurence_of Fiche class Type
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   570
     Sheet class Type    <-> Form collection Collection class Type
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   571
    
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   572
Therefore 1. becomes::
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   573
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   574
     Document X where
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   575
     X class C, C name 'Cartoon'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   576
     X owned_by U, U login 'syt'
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   577
     X available true
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   578
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   579
I'm not sure that we should handle this at RQL level ...
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   580
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   581
There should also be a special relation 'anonymous'.
115
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   582
4b66ad23fbd1 [doc] merge old lax book with the rest
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 113
diff changeset
   583
209
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   584
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   585
.. _Versa: Http://uche.ogbuji.net/tech/rdf/versa/
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   586
.. _RDFQL: Http://www.w3.org/TandS/QL/QL98/pp/rdfquery.html
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   587
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   588
38a9c240ac64 [doc] Now uses specs from rql/doc
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
   589
XXX see also RQL documentation in source rql/doc.