File: queries.sql

package info (click to toggle)
prefix 1.2.3-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 688 kB
  • ctags: 150
  • sloc: ansic: 1,313; sql: 756; makefile: 36; sh: 2
file content (42 lines) | stat: -rw-r--r-- 1,554 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
-- operators
select a, b,
   a <= b as "<=", a < b as "<", a = b as "=", a <> b as "<>", a >= b as ">=", a > b as ">",
   a @> b as "@>", a <@ b as "<@", a && b as "&&"
from  (select a::prefix_range, b::prefix_range
         from (values('123', '123'),
                     ('123', '124'),
                     ('123', '123[4-5]'),
                     ('123[4-5]', '123[2-7]'),
                     ('123', '[2-3]')) as t(a, b)
      ) as x;

-- transitivity
select a, b, c, a <= b as "a <= b", b <= c as "b <= c", a <= c as "a <= c"
from  (select a::prefix_range, b::prefix_range, c::prefix_range
         from (values('123', '123', '123'),
                     ('123', '124', '125'),
                     ('123', '123[4-5]', '123[4-6]'),
                     ('123[4-5]', '123[2-7]', '123[1-8]'),
                     ('123', '[2-3]', '4')) as t(a, b, c)
      ) as x;

-- set operations
select a, b, a | b as union, a & b as intersect
  from  (select a::prefix_range, b::prefix_range
           from (values('123', '123'),
                       ('123', '124'),
                       ('123', '123[4-5]'),
                       ('123[4-5]', '123[2-7]'),
                       ('123', '[2-3]')) as t(a, b)
        ) as x;

-- casting to and from text
select prefix_range('123');
select prefix_range('123[4-5]');
select prefix_range('[2-3]');
select prefix_range('123', '4', '5');
select length('12345'::prefix_range);
select length('12345[]'::prefix_range);
select length('123[4-5]'::prefix_range);
select length('1234'::prefix_range);
\dC *prefix*