forked from MaterializeInc/materialize
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoperator.slt
151 lines (119 loc) · 2.67 KB
/
operator.slt
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
statement OK
CREATE TABLE tbl(string text);
statement OK
INSERT INTO tbl(string)
SELECT x::text FROM generate_series(1, 10000) x;
query I
select 2 OPERATOR(*) 2;
----
4
query I
select 2 OPERATOR(+) 2;
----
4
query I
select 2 OPERATOR(-) 2;
----
0
query I
select 2 OPERATOR(/) 2
----
1
query I
select 2 OPERATOR(pg_catalog.*) 2;
----
4
query I
select 2 OPERATOR(pg_catalog.+) 2;
----
4
query I
select 2 OPERATOR(pg_catalog.-) 2;
----
0
query I
select 2 OPERATOR(pg_catalog./) 2
----
1
query error operator does not exist: mz_catalog.*
select 2 OPERATOR(mz_catalog.*) 2;
query error operator does not exist: mz_catalog.public.*
select 2 OPERATOR(mz_catalog.public.*) 2;
query error Expected operator, found number "5."
select 2 OPERATOR(5.*) 2;
# confirm the precedence of the OPERATOR
query I
select 2 OPERATOR(*) 2 + 2;
----
8
query I
select 2 OPERATOR(*) 2 OPERATOR(+) 2;
----
6
query I
select 2 * 2 OPERATOR(+) 2;
----
6
query T
SELECT * FROM tbl WHERE string ~ '^1234'
----
1234
query T
SELECT * FROM tbl WHERE string OPERATOR(~) '^1234'
----
1234
query T
SELECT * FROM tbl WHERE string OPERATOR(pg_catalog.~) '^1234'
----
1234
query T
SELECT * FROM tbl WHERE string ~ '^123$'
----
123
query T
SELECT * FROM tbl WHERE string OPERATOR(~) '^123$'
----
123
query T
SELECT * FROM tbl WHERE string OPERATOR(pg_catalog.~) '^123$'
----
123
# Confirm that operators can be used in views
statement ok
CREATE VIEW PG_ADDER AS SELECT 2 OPERATOR(pg_catalog.+) 2;
query TT
SHOW CREATE VIEW PG_ADDER
----
materialize.public.pg_adder
CREATE VIEW "materialize"."public"."pg_adder" AS SELECT 2 OPERATOR(pg_catalog.+) 2
statement ok
CREATE VIEW ADDER AS SELECT 2 OPERATOR(+) 2;
query TT
SHOW CREATE VIEW ADDER
----
materialize.public.adder
CREATE VIEW "materialize"."public"."adder" AS SELECT 2 + 2
statement ok
CREATE VIEW MULTIPLIER AS SELECT 2 OPERATOR(*) 2;
query TT
SHOW CREATE VIEW MULTIPLIER
----
materialize.public.multiplier
CREATE VIEW "materialize"."public"."multiplier" AS SELECT 2 * 2
statement ok
CREATE VIEW PG_MULTIPLIER AS SELECT 2 OPERATOR(pg_catalog.*) 2;
query TT
SHOW CREATE VIEW PG_MULTIPLIER
----
materialize.public.pg_multiplier
CREATE VIEW "materialize"."public"."pg_multiplier" AS SELECT 2 OPERATOR(pg_catalog.*) 2
query error Expected operator, found number "5."
CREATE VIEW INVALID_FIVE AS select 2 OPERATOR(5.*) 2;