forked from MaterializeInc/materialize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbytea.slt
139 lines (112 loc) · 2.29 KB
/
bytea.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
# 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.
# Tests for the bytea type.
mode cockroach
statement ok
CREATE TABLE test (ord int, b bytea)
statement ok
INSERT INTO test VALUES (0, 'hello'), (1, '你好'), (2, NULL), (3, ''), (4, 'nonprintablechar:')
query II rowsort
SELECT ord, length(b) FROM test
----
0 5
1 6
2 NULL
3 0
4 18
query II rowsort
SELECT ord, length(b, 'utf-8') FROM test
----
0 5
1 2
2 NULL
3 0
4 18
query I
SELECT length('\xDEADBEEF'::bytea)
----
4
query I
SELECT octet_length('\xDEADBEEF'::bytea)
----
4
query I
SELECT bit_length('\xDEADBEEF'::bytea)
----
32
query I
SELECT length('DEADBEEF'::bytea)
----
8
query I
SELECT octet_length('DEADBEEF'::bytea)
----
8
query I
SELECT octet_length('DEADBEEF'::text);
----
8
query I
SELECT bit_length('DEADBEEF'::bytea)
----
64
query I
SELECT bit_length('DEADBEEF'::text);
----
64
statement error
SELECT length('deadbeef'::text, 'utf-8')
query IT rowsort
SELECT ord, b::text FROM test
----
0 \x68656c6c6f
1 \xe4bda0e5a5bd
2 NULL
3 \x
4 \x6e6f6e7072696e7461626c65636861723a06
query IT rowsort
SELECT ord, convert_from(b, 'utf-8') FROM test
----
0 hello
1 你好
2 NULL
3 (empty)
4 nonprintablechar:
query error invalid encoding name 'invalid encoding'
SELECT convert_from(b, 'invalid encoding') FROM test
query error invalid utf-8 sequence of 1 bytes
SELECT convert_from('\x00ff', 'utf-8')
# get_byte
statement ok
CREATE TABLE test_value (v bytea);
statement ok
INSERT INTO test_value VALUES ('\x1234567890'::bytea);
query error index -1 out of valid range, 0..4
SELECT get_byte(v, -1) FROM test_value
query error index 5 out of valid range, 0..4
SELECT get_byte(v, 5) FROM test_value
query error index 0 out of valid range, 0..-1
SELECT get_byte('\x'::bytea, 0)
query IIIIII
SELECT
get_byte(v, 0),
get_byte(v, 1),
get_byte(v, 2),
get_byte(v, 3),
get_byte(v, 4),
get_byte(v, NULL)
FROM test_value
----
18 52 86 120 144 NULL
query II
SELECT
get_byte(NULL, 0),
get_byte(NULL, 2);
----
NULL NULL