List of articles   Terminology   Choose language


Syntax of SQL/XLang


Extracted fields

Fields, which must be selected, are listed in XTree-expression after service word 'from' (extracted sections are listed after service word 'select' - look below). If no one field is specified, then it's equivalent of specification of all fields.

select * from a.b[@b1 @b2]; -- select only "b1" and "b2" from "b"
select * from a.b;          -- select all fields from "b"
                            -- (except used references fields)
Fields can be re-named.
select * from a.b[@b1 as @m,    @b2 as @n];
select * from a.b[@b1 as @m and @b2 as @n];

Extracted sections

Part of sections of tree can be hidden for output. Whole tree is written after service word 'from', and extracted fields after service word 'select'.

select b.d
from   a.b.c.d;      -- extracts
                     --   <b>
                     --     <d><d>
                     --   </b>
                     --   <b>
                     --     <d><d>
                     --   </b>

Virtual foreign keys

It's possible to specify virtual (temporaty, to period of action of one sql-expression) foreign key for constructions like 'a.b.k.m', where "a" and "b" are bound by foreign key (FK), "k" and "m" are bound by foreign key, but there is no foreign key between "b" and "k". Virtual foreign keys are listed after service word 'where'.

Thus SQL/XLang works not only with separate tables, but with conglomerates of tables (with trees).

select a.b.k.m
from   a.b , k.m     -- trees "a.b" and "k.m" must physically exist
where  b/@b1=k/@k1   -- virtual FK to join 'a.b' and 'k.m' into 'a.b.k.m'

It's possible to specify virtual foreign key after service word 'where', binding previous and next "b", for constructions like 'a.b*.c' and 'a.b+.c', where "a" and "b" are bound by foreign key (FK), "b" and "c" are bound by foreign key, but "b" does not refer to itself by foreign key. Previous and next "b" are specified in functions previous and next.

select *
from   a.b*.c
where  previous(b).b2=next(b).b1  -- virtual FK, something similar
                     -- select x.y
                     -- from b x y
                     -- where x.b2=y.b1

Aliases of tables and virtual FK

Aliases of table are listed after service word 'from' as before. Aliases can be used to specify virtual foreign keys too.

select p.q.r
from   c p q r       -- "p, q, r" are alias-es of "c"
where  p/@c2=q/@c3   --  virtual FK
  and  q/@c4=r/@c5;  --  virtual FK
select a.b.p.q.r
from   a.b, c p q r  -- "p, q, r" are alias-es of "c"
where  b/@b1=p/@c1   --  virtual FK
  and  p/@c2=q/@c3   --  virtual FK
  and  q/@c4=r/@c5;  --  virtual FK

Conditions for fields

Relationships, binding fields of tree, can be listed both after service word 'from', and after service word 'where'.

Examples from the left and from the right are equivalent.
from a.b[@b1=5]
from a.b[@b1]
from a.b.c[@c1=../../@a1]
from a.b[position()=1 xor @b1=5]*.c
from a.b[last() xor @b1=5]*.c
from a.b    where @b1=5            -- where b/@b1=5
from a.b    where @b1 is not null
from a.b.c  where @a1=@c1          -- where a/@a1=c/@c1
from a.b*.c where first(b)/@b1=5; 
from a.b*.c where last(b)/@b1=5;
Relationships between field and set are listed after service word 'where'.
where @b1 in (select ... )                                                   -- where b/@b1 in (select ... )

Rejection from previous designation

To not enter user into error and to not bring frustration in wit, it's necessary to reject three old designations and replace them by new designations.

select a.a1
select a/@a1     -- old notation to request fields instead of sections
where b.b1=5
where b/@b1=5
from scheme.tab
from scheme§tab  -- database%scheme§tab

Dmitry Turin



List of articles   Terminology   Choose language


Сайт управляется системой uCoz