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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
|
<sql-statement>
--
-- BIT types
--
--
-- Build tables for testing
--
CREATE TABLE BIT_TABLE(b BIT(11));
</sql-statement>
<sql-statement>
INSERT INTO BIT_TABLE VALUES (B'10'); -- too short
</sql-statement>
<sql-statement>
INSERT INTO BIT_TABLE VALUES (B'00000000000');
</sql-statement>
<sql-statement>
INSERT INTO BIT_TABLE VALUES (B'11011000000');
</sql-statement>
<sql-statement>
INSERT INTO BIT_TABLE VALUES (B'01010101010');
</sql-statement>
<sql-statement>
INSERT INTO BIT_TABLE VALUES (B'101011111010'); -- too long
</sql-statement>
<sql-statement>
--INSERT INTO BIT_TABLE VALUES ('X554');
--INSERT INTO BIT_TABLE VALUES ('X555');
SELECT * FROM BIT_TABLE;
</sql-statement>
<sql-statement>
CREATE TABLE VARBIT_TABLE(v BIT VARYING(11));
</sql-statement>
<sql-statement>
INSERT INTO VARBIT_TABLE VALUES (B'');
</sql-statement>
<sql-statement>
INSERT INTO VARBIT_TABLE VALUES (B'0');
</sql-statement>
<sql-statement>
INSERT INTO VARBIT_TABLE VALUES (B'010101');
</sql-statement>
<sql-statement>
INSERT INTO VARBIT_TABLE VALUES (B'01010101010');
</sql-statement>
<sql-statement>
INSERT INTO VARBIT_TABLE VALUES (B'101011111010'); -- too long
</sql-statement>
<sql-statement>
--INSERT INTO VARBIT_TABLE VALUES ('X554');
--INSERT INTO VARBIT_TABLE VALUES ('X555');
SELECT * FROM VARBIT_TABLE;
</sql-statement>
<sql-statement>
-- Concatenation
SELECT v, b, (v || b) AS concat
FROM BIT_TABLE, VARBIT_TABLE
ORDER BY 3;
</sql-statement>
<sql-statement>
-- Length
SELECT b, length(b) AS lb
FROM BIT_TABLE;
</sql-statement>
<sql-statement>
SELECT v, length(v) AS lv
FROM VARBIT_TABLE;
</sql-statement>
<sql-statement>
-- Substring
SELECT b,
SUBSTRING(b FROM 2 FOR 4) AS sub_2_4,
SUBSTRING(b FROM 7 FOR 13) AS sub_7_13,
SUBSTRING(b FROM 6) AS sub_6
FROM BIT_TABLE;
</sql-statement>
<sql-statement>
SELECT v,
SUBSTRING(v FROM 2 FOR 4) AS sub_2_4,
SUBSTRING(v FROM 7 FOR 13) AS sub_7_13,
SUBSTRING(v FROM 6) AS sub_6
FROM VARBIT_TABLE;
</sql-statement>
<sql-statement>
-- test overflow cases
SELECT SUBSTRING('01010101'::bit(8) FROM 2 FOR 2147483646) AS "1010101";
</sql-statement>
<sql-statement>
SELECT SUBSTRING('01010101'::bit(8) FROM -10 FOR 2147483646) AS "01010101";
</sql-statement>
<sql-statement>
SELECT SUBSTRING('01010101'::bit(8) FROM -10 FOR -2147483646) AS "error";
</sql-statement>
-stdin-:<main>: Fatal: Execution
-stdin-:<main>:1:1: Fatal: Execution of node: Result
SELECT SUBSTRING('01010101'::bit(8) FROM -10 FOR -2147483646) AS "error";
^
-stdin-:<main>:1:1: Fatal: ERROR: negative substring length not allowed
SELECT SUBSTRING('01010101'::bit(8) FROM -10 FOR -2147483646) AS "error";
^
<sql-statement>
SELECT SUBSTRING('01010101'::varbit FROM 2 FOR 2147483646) AS "1010101";
</sql-statement>
<sql-statement>
SELECT SUBSTRING('01010101'::varbit FROM -10 FOR 2147483646) AS "01010101";
</sql-statement>
<sql-statement>
SELECT SUBSTRING('01010101'::varbit FROM -10 FOR -2147483646) AS "error";
</sql-statement>
-stdin-:<main>: Fatal: Execution
-stdin-:<main>:1:1: Fatal: Execution of node: Result
SELECT SUBSTRING('01010101'::varbit FROM -10 FOR -2147483646) AS "error";
^
-stdin-:<main>:1:1: Fatal: ERROR: negative substring length not allowed
SELECT SUBSTRING('01010101'::varbit FROM -10 FOR -2147483646) AS "error";
^
<sql-statement>
--- Bit operations
DROP TABLE varbit_table;
</sql-statement>
<sql-statement>
CREATE TABLE varbit_table (a BIT VARYING(16), b BIT VARYING(16));
</sql-statement>
<sql-statement>
COPY varbit_table FROM stdin;
X0F X10
X1F X11
X2F X12
X3F X13
X8F X04
X000F X0010
X0123 XFFFF
X2468 X2468
XFA50 X05AF
X1234 XFFF5
\.
</sql-statement>
Metacommand \. is not supported
<sql-statement>
SELECT a, b, ~a AS "~ a", a & b AS "a & b",
a | b AS "a | b", a # b AS "a # b" FROM varbit_table;
</sql-statement>
<sql-statement>
SELECT a,b,a<b AS "a<b",a<=b AS "a<=b",a=b AS "a=b",
a>=b AS "a>=b",a>b AS "a>b",a<>b AS "a<>b" FROM varbit_table;
</sql-statement>
<sql-statement>
SELECT a,a<<4 AS "a<<4",b,b>>2 AS "b>>2" FROM varbit_table;
</sql-statement>
<sql-statement>
DROP TABLE varbit_table;
</sql-statement>
<sql-statement>
--- Bit operations
DROP TABLE bit_table;
</sql-statement>
<sql-statement>
CREATE TABLE bit_table (a BIT(16), b BIT(16));
</sql-statement>
<sql-statement>
COPY bit_table FROM stdin;
X0F00 X1000
X1F00 X1100
X2F00 X1200
X3F00 X1300
X8F00 X0400
X000F X0010
X0123 XFFFF
X2468 X2468
XFA50 X05AF
X1234 XFFF5
\.
</sql-statement>
Metacommand \. is not supported
<sql-statement>
SELECT a,b,~a AS "~ a",a & b AS "a & b",
a|b AS "a | b", a # b AS "a # b" FROM bit_table;
</sql-statement>
<sql-statement>
SELECT a,b,a<b AS "a<b",a<=b AS "a<=b",a=b AS "a=b",
a>=b AS "a>=b",a>b AS "a>b",a<>b AS "a<>b" FROM bit_table;
</sql-statement>
<sql-statement>
SELECT a,a<<4 AS "a<<4",b,b>>2 AS "b>>2" FROM bit_table;
</sql-statement>
<sql-statement>
DROP TABLE bit_table;
</sql-statement>
<sql-statement>
-- The following should fail
select B'001' & B'10';
</sql-statement>
-stdin-:<main>: Fatal: Execution
-stdin-:<main>:1:1: Fatal: Execution of node: Result
-- The following should fail
^
-stdin-:<main>:1:1: Fatal: ERROR: cannot AND bit strings of different sizes
-- The following should fail
^
<sql-statement>
select B'0111' | B'011';
</sql-statement>
-stdin-:<main>: Fatal: Execution
-stdin-:<main>:1:1: Fatal: Execution of node: Result
select B'0111' | B'011';
^
-stdin-:<main>:1:1: Fatal: ERROR: cannot OR bit strings of different sizes
select B'0111' | B'011';
^
<sql-statement>
select B'0010' # B'011101';
</sql-statement>
-stdin-:<main>: Fatal: Execution
-stdin-:<main>:1:1: Fatal: Execution of node: Result
select B'0010' # B'011101';
^
-stdin-:<main>:1:1: Fatal: ERROR: cannot XOR bit strings of different sizes
select B'0010' # B'011101';
^
<sql-statement>
-- More position tests, checking all the boundary cases
SELECT POSITION(B'1010' IN B'0000101'); -- 0
</sql-statement>
<sql-statement>
SELECT POSITION(B'1010' IN B'00001010'); -- 5
</sql-statement>
<sql-statement>
SELECT POSITION(B'1010' IN B'00000101'); -- 0
</sql-statement>
<sql-statement>
SELECT POSITION(B'1010' IN B'000001010'); -- 6
</sql-statement>
<sql-statement>
SELECT POSITION(B'' IN B'00001010'); -- 1
</sql-statement>
<sql-statement>
SELECT POSITION(B'0' IN B''); -- 0
</sql-statement>
<sql-statement>
SELECT POSITION(B'' IN B''); -- 0
</sql-statement>
<sql-statement>
SELECT POSITION(B'101101' IN B'001011011011011000'); -- 3
</sql-statement>
<sql-statement>
SELECT POSITION(B'10110110' IN B'001011011011010'); -- 3
</sql-statement>
<sql-statement>
SELECT POSITION(B'1011011011011' IN B'001011011011011'); -- 3
</sql-statement>
<sql-statement>
SELECT POSITION(B'1011011011011' IN B'00001011011011011'); -- 5
</sql-statement>
<sql-statement>
SELECT POSITION(B'11101011' IN B'11101011'); -- 1
</sql-statement>
<sql-statement>
SELECT POSITION(B'11101011' IN B'011101011'); -- 2
</sql-statement>
<sql-statement>
SELECT POSITION(B'11101011' IN B'00011101011'); -- 4
</sql-statement>
<sql-statement>
SELECT POSITION(B'11101011' IN B'0000011101011'); -- 6
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'111010110'); -- 1
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'0111010110'); -- 2
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'000111010110'); -- 4
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'00000111010110'); -- 6
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'11101011'); -- 0
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'011101011'); -- 0
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'00011101011'); -- 0
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'0000011101011'); -- 0
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'111010110'); -- 1
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'0111010110'); -- 2
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'000111010110'); -- 4
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'00000111010110'); -- 6
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'000001110101111101011'); -- 0
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'0000001110101111101011'); -- 0
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'000000001110101111101011'); -- 0
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'00000000001110101111101011'); -- 0
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'0000011101011111010110'); -- 14
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'00000011101011111010110'); -- 15
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'0000000011101011111010110'); -- 17
</sql-statement>
<sql-statement>
SELECT POSITION(B'111010110' IN B'000000000011101011111010110'); -- 19
</sql-statement>
<sql-statement>
SELECT POSITION(B'000000000011101011111010110' IN B'000000000011101011111010110'); -- 1
</sql-statement>
<sql-statement>
SELECT POSITION(B'00000000011101011111010110' IN B'000000000011101011111010110'); -- 2
</sql-statement>
<sql-statement>
SELECT POSITION(B'0000000000011101011111010110' IN B'000000000011101011111010110'); -- 0
</sql-statement>
<sql-statement>
-- Shifting
CREATE TABLE BIT_SHIFT_TABLE(b BIT(16));
</sql-statement>
<sql-statement>
INSERT INTO BIT_SHIFT_TABLE VALUES (B'1101100000000000');
</sql-statement>
<sql-statement>
INSERT INTO BIT_SHIFT_TABLE SELECT b>>1 FROM BIT_SHIFT_TABLE;
</sql-statement>
<sql-statement>
INSERT INTO BIT_SHIFT_TABLE SELECT b>>2 FROM BIT_SHIFT_TABLE;
</sql-statement>
<sql-statement>
INSERT INTO BIT_SHIFT_TABLE SELECT b>>4 FROM BIT_SHIFT_TABLE;
</sql-statement>
<sql-statement>
INSERT INTO BIT_SHIFT_TABLE SELECT b>>8 FROM BIT_SHIFT_TABLE;
</sql-statement>
<sql-statement>
SELECT POSITION(B'1101' IN b),
POSITION(B'11011' IN b),
b
FROM BIT_SHIFT_TABLE ;
</sql-statement>
-stdin-:<main>: Error: Type annotation
-stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem
SELECT POSITION(B'1101' IN b),
^
-stdin-:<main>:1:1: Error: Duplicated member: position
SELECT POSITION(B'1101' IN b),
^
<sql-statement>
SELECT b, b >> 1 AS bsr, b << 1 AS bsl
FROM BIT_SHIFT_TABLE ;
</sql-statement>
<sql-statement>
SELECT b, b >> 8 AS bsr8, b << 8 AS bsl8
FROM BIT_SHIFT_TABLE ;
</sql-statement>
<sql-statement>
SELECT b::bit(15), b::bit(15) >> 1 AS bsr, b::bit(15) << 1 AS bsl
FROM BIT_SHIFT_TABLE ;
</sql-statement>
<sql-statement>
SELECT b::bit(15), b::bit(15) >> 8 AS bsr8, b::bit(15) << 8 AS bsl8
FROM BIT_SHIFT_TABLE ;
</sql-statement>
<sql-statement>
CREATE TABLE VARBIT_SHIFT_TABLE(v BIT VARYING(20));
</sql-statement>
<sql-statement>
INSERT INTO VARBIT_SHIFT_TABLE VALUES (B'11011');
</sql-statement>
<sql-statement>
INSERT INTO VARBIT_SHIFT_TABLE SELECT CAST(v || B'0' AS BIT VARYING(6)) >>1 FROM VARBIT_SHIFT_TABLE;
</sql-statement>
<sql-statement>
INSERT INTO VARBIT_SHIFT_TABLE SELECT CAST(v || B'00' AS BIT VARYING(8)) >>2 FROM VARBIT_SHIFT_TABLE;
</sql-statement>
<sql-statement>
INSERT INTO VARBIT_SHIFT_TABLE SELECT CAST(v || B'0000' AS BIT VARYING(12)) >>4 FROM VARBIT_SHIFT_TABLE;
</sql-statement>
<sql-statement>
INSERT INTO VARBIT_SHIFT_TABLE SELECT CAST(v || B'00000000' AS BIT VARYING(20)) >>8 FROM VARBIT_SHIFT_TABLE;
</sql-statement>
<sql-statement>
SELECT POSITION(B'1101' IN v),
POSITION(B'11011' IN v),
v
FROM VARBIT_SHIFT_TABLE ;
</sql-statement>
-stdin-:<main>: Error: Type annotation
-stdin-:<main>:1:1: Error: At function: RemovePrefixMembers, At function: PgSelect, At function: PgSetItem
SELECT POSITION(B'1101' IN v),
^
-stdin-:<main>:1:1: Error: Duplicated member: position
SELECT POSITION(B'1101' IN v),
^
<sql-statement>
SELECT v, v >> 1 AS vsr, v << 1 AS vsl
FROM VARBIT_SHIFT_TABLE ;
</sql-statement>
<sql-statement>
SELECT v, v >> 8 AS vsr8, v << 8 AS vsl8
FROM VARBIT_SHIFT_TABLE ;
</sql-statement>
<sql-statement>
DROP TABLE BIT_SHIFT_TABLE;
</sql-statement>
<sql-statement>
DROP TABLE VARBIT_SHIFT_TABLE;
</sql-statement>
<sql-statement>
-- Get/Set bit
SELECT get_bit(B'0101011000100', 10);
</sql-statement>
<sql-statement>
SELECT set_bit(B'0101011000100100', 15, 1);
</sql-statement>
<sql-statement>
SELECT set_bit(B'0101011000100100', 16, 1); -- fail
</sql-statement>
-stdin-:<main>: Fatal: Execution
-stdin-:<main>:1:1: Fatal: Execution of node: Result
SELECT set_bit(B'0101011000100100', 16, 1); -- fail
^
-stdin-:<main>:1:1: Fatal: ERROR: bit index 16 out of valid range (0..15)
SELECT set_bit(B'0101011000100100', 16, 1); -- fail
^
<sql-statement>
-- Overlay
SELECT overlay(B'0101011100' placing '001' from 2 for 3);
</sql-statement>
<sql-statement>
SELECT overlay(B'0101011100' placing '101' from 6);
</sql-statement>
<sql-statement>
SELECT overlay(B'0101011100' placing '001' from 11);
</sql-statement>
<sql-statement>
SELECT overlay(B'0101011100' placing '001' from 20);
</sql-statement>
<sql-statement>
-- bit_count
SELECT bit_count(B'0101011100'::bit(10));
</sql-statement>
<sql-statement>
SELECT bit_count(B'1111111111'::bit(10));
</sql-statement>
<sql-statement>
-- This table is intentionally left around to exercise pg_dump/pg_upgrade
CREATE TABLE bit_defaults(
b1 bit(4) DEFAULT '1001',
b2 bit(4) DEFAULT B'0101',
b3 bit varying(5) DEFAULT '1001',
b4 bit varying(5) DEFAULT B'0101'
);
</sql-statement>
<sql-statement>
\d bit_defaults
</sql-statement>
Metacommand \d bit_defaults is not supported
<sql-statement>
INSERT INTO bit_defaults DEFAULT VALUES;
</sql-statement>
-stdin-:<main>: Fatal: tools/enum_parser/enum_serialization_runtime/enum_runtime.cpp:70: Key 'default_values' not found in enum NYql::EYtSettingType. Valid options are: 'initial', 'infer_scheme', 'force_infer_schema', 'do_not_fail_on_invalid_schema', 'direct_read', 'view', 'mode', 'scheme', 'weak_concat', 'anonymous', 'with_qb', 'inline', 'sample', 'joinLabel', 'ignore_non_existing', 'warn_non_existing', 'xlock', 'unordered', 'nonUnique', 'userschema', 'usercolumns', 'statcolumns', 'syscolumns', 'ignoretypev3', 'memUsage', 'itemsCount', 'rowFactor', 'ordered', 'keyFilter', 'keyFilter2', 'take', 'skip', 'limit', 'sortLimitBy', 'sortBy', 'reduceBy', 'reduceFilterBy', 'forceTransform', 'weakFields', 'sharded', 'combineChunks', 'jobCount', 'joinReduce', 'firstAsPrimary', 'flow', 'keepSorted', 'keySwitch', 'uniqueBy', 'opHash', 'mapOutputType', 'reduceInputType', 'noDq', 'split', 'compression_codec', 'erasure_codec', 'expiration', 'replication_factor', 'user_attrs', 'media', 'primary_medium', 'keep_meta', 'monotonic_keys', 'mutationid'.
<sql-statement>
TABLE bit_defaults;
</sql-statement>
|