Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
f31844f1
Commit
f31844f1
authored
Nov 22, 2000
by
Peter Eisentraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bit string regression test
from Adriaan Joubert <a.joubert@albourne.com>
parent
0edf928f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
719 additions
and
2 deletions
+719
-2
src/test/regress/expected/bit.out
src/test/regress/expected/bit.out
+530
-0
src/test/regress/parallel_schedule
src/test/regress/parallel_schedule
+1
-1
src/test/regress/serial_schedule
src/test/regress/serial_schedule
+2
-1
src/test/regress/sql/bit.sql
src/test/regress/sql/bit.sql
+186
-0
No files found.
src/test/regress/expected/bit.out
0 → 100644
View file @
f31844f1
--
-- BIT types
--
--
-- Build tables for testing
--
CREATE TABLE ZPBIT_TABLE(b BIT(11));
INSERT INTO ZPBIT_TABLE VALUES (B'');
INSERT INTO ZPBIT_TABLE VALUES (B'0');
INSERT INTO ZPBIT_TABLE VALUES (B'11011');
INSERT INTO ZPBIT_TABLE VALUES (B'01010101010');
INSERT INTO ZPBIT_TABLE VALUES (B'101011111010'); -- too long
--INSERT INTO ZPBIT_TABLE VALUES ('X554');
--INSERT INTO ZPBIT_TABLE VALUES ('X555');
SELECT * FROM ZPBIT_TABLE;
b
-------------
00000000000
00000000000
11011000000
01010101010
10101111101
(5 rows)
CREATE TABLE VARBIT_TABLE(v BIT VARYING(11));
INSERT INTO VARBIT_TABLE VALUES (B'');
INSERT INTO VARBIT_TABLE VALUES (B'0');
INSERT INTO VARBIT_TABLE VALUES (B'010101');
INSERT INTO VARBIT_TABLE VALUES (B'01010101010');
INSERT INTO VARBIT_TABLE VALUES (B'101011111010'); -- too long
--INSERT INTO VARBIT_TABLE VALUES ('X554');
--INSERT INTO VARBIT_TABLE VALUES ('X555');
SELECT * FROM VARBIT_TABLE;
v
-------------
0
010101
01010101010
10101111101
(5 rows)
-- Concatenation
SELECT v, b, (v || b) AS concat
FROM ZPBIT_TABLE, VARBIT_TABLE
ORDER BY 3;
v | b | concat
-------------+-------------+------------------------
| 00000000000 | 00000000000
| 00000000000 | 00000000000
0 | 00000000000 | 000000000000
0 | 00000000000 | 000000000000
0 | 01010101010 | 001010101010
010101 | 00000000000 | 01010100000000000
010101 | 00000000000 | 01010100000000000
| 01010101010 | 01010101010
01010101010 | 00000000000 | 0101010101000000000000
01010101010 | 00000000000 | 0101010101000000000000
01010101010 | 01010101010 | 0101010101001010101010
010101 | 01010101010 | 01010101010101010
01010101010 | 10101111101 | 0101010101010101111101
01010101010 | 11011000000 | 0101010101011011000000
010101 | 10101111101 | 01010110101111101
010101 | 11011000000 | 01010111011000000
0 | 10101111101 | 010101111101
0 | 11011000000 | 011011000000
| 10101111101 | 10101111101
10101111101 | 00000000000 | 1010111110100000000000
10101111101 | 00000000000 | 1010111110100000000000
10101111101 | 01010101010 | 1010111110101010101010
10101111101 | 10101111101 | 1010111110110101111101
10101111101 | 11011000000 | 1010111110111011000000
| 11011000000 | 11011000000
(25 rows)
-- Length
SELECT b, length(b) AS lb
FROM ZPBIT_TABLE;
b | lb
-------------+----
00000000000 | 11
00000000000 | 11
11011000000 | 11
01010101010 | 11
10101111101 | 11
(5 rows)
SELECT v, length(v) AS lv
FROM VARBIT_TABLE;
v | lv
-------------+----
| 0
0 | 1
010101 | 6
01010101010 | 11
10101111101 | 11
(5 rows)
-- 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 ZPBIT_TABLE;
b | sub_2_4 | sub_7_13 | sub_6
-------------+---------+----------+--------
00000000000 | 0000 | 00000 | 000000
00000000000 | 0000 | 00000 | 000000
11011000000 | 1011 | 00000 | 000000
01010101010 | 1010 | 01010 | 101010
10101111101 | 0101 | 11101 | 111101
(5 rows)
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;
v | sub_2_4 | sub_7_13 | sub_6
-------------+---------+----------+--------
| | |
0 | | |
010101 | 1010 | | 1
01010101010 | 1010 | 01010 | 101010
10101111101 | 0101 | 11101 | 111101
(5 rows)
--- Bit operations
DROP TABLE varbit_table;
CREATE TABLE varbit_table (a BIT VARYING(16), b BIT VARYING(16));
COPY varbit_table FROM stdin;
SELECT a, b, ~a AS "~ a", a & b AS "a & b",
a | b AS "a | b", a # b AS "a # b" FROM varbit_table;
a | b | ~ a | a & b | a | b | a # b
------------------+------------------+------------------+------------------+------------------+------------------
00001111 | 00010000 | 11110000 | 00000000 | 00011111 | 00011111
00011111 | 00010001 | 11100000 | 00010001 | 00011111 | 00001110
00101111 | 00010010 | 11010000 | 00000010 | 00111111 | 00111101
00111111 | 00010011 | 11000000 | 00010011 | 00111111 | 00101100
10001111 | 00000100 | 01110000 | 00000100 | 10001111 | 10001011
0000000000001111 | 0000000000010000 | 1111111111110000 | 0000000000000000 | 0000000000011111 | 0000000000011111
0000000100100011 | 1111111111111111 | 1111111011011100 | 0000000100100011 | 1111111111111111 | 1111111011011100
0010010001101000 | 0010010001101000 | 1101101110010111 | 0010010001101000 | 0010010001101000 | 0000000000000000
1111101001010000 | 0000010110101111 | 0000010110101111 | 0000000000000000 | 1111111111111111 | 1111111111111111
0001001000110100 | 1111111111110101 | 1110110111001011 | 0001001000110100 | 1111111111110101 | 1110110111000001
(10 rows)
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;
a | b | a<b | a<=b | a=b | a>=b | a>b | a<>b
------------------+------------------+-----+------+-----+------+-----+------
00001111 | 00010000 | t | t | f | f | f | t
00011111 | 00010001 | f | f | f | t | t | t
00101111 | 00010010 | f | f | f | t | t | t
00111111 | 00010011 | f | f | f | t | t | t
10001111 | 00000100 | f | f | f | t | t | t
0000000000001111 | 0000000000010000 | t | t | f | f | f | t
0000000100100011 | 1111111111111111 | t | t | f | f | f | t
0010010001101000 | 0010010001101000 | f | t | t | t | f | f
1111101001010000 | 0000010110101111 | f | f | f | t | t | t
0001001000110100 | 1111111111110101 | t | t | f | f | f | t
(10 rows)
SELECT a,a<<4 AS "a<<4",b,b>>2 AS "b>>2" FROM varbit_table;
a | a<<4 | b | b>>2
------------------+------------------+------------------+------------------
00001111 | 11110000 | 00010000 | 00000100
00011111 | 11110000 | 00010001 | 00000100
00101111 | 11110000 | 00010010 | 00000100
00111111 | 11110000 | 00010011 | 00000100
10001111 | 11110000 | 00000100 | 00000001
0000000000001111 | 0000000011110000 | 0000000000010000 | 0000000000000100
0000000100100011 | 0001001000110000 | 1111111111111111 | 0011111111111111
0010010001101000 | 0100011010000000 | 0010010001101000 | 0000100100011010
1111101001010000 | 1010010100000000 | 0000010110101111 | 0000000101101011
0001001000110100 | 0010001101000000 | 1111111111110101 | 0011111111111101
(10 rows)
DROP TABLE varbit_table;
--- Bit operations
DROP TABLE zpbit_table;
CREATE TABLE zpbit_table (a BIT(16), b BIT(16));
COPY zpbit_table FROM stdin;
SELECT a,b,~a AS "~ a",a & b AS "a & b",
a|b AS "a | b", a # b AS "a # b" FROM zpbit_table;
a | b | ~ a | a & b | a | b | a # b
------------------+------------------+------------------+------------------+------------------+------------------
0000111100000000 | 0001000000000000 | 1111000011111111 | 0000000000000000 | 0001111100000000 | 0001111100000000
0001111100000000 | 0001000100000000 | 1110000011111111 | 0001000100000000 | 0001111100000000 | 0000111000000000
0010111100000000 | 0001001000000000 | 1101000011111111 | 0000001000000000 | 0011111100000000 | 0011110100000000
0011111100000000 | 0001001100000000 | 1100000011111111 | 0001001100000000 | 0011111100000000 | 0010110000000000
1000111100000000 | 0000010000000000 | 0111000011111111 | 0000010000000000 | 1000111100000000 | 1000101100000000
0000000000001111 | 0000000000010000 | 1111111111110000 | 0000000000000000 | 0000000000011111 | 0000000000011111
0000000100100011 | 1111111111111111 | 1111111011011100 | 0000000100100011 | 1111111111111111 | 1111111011011100
0010010001101000 | 0010010001101000 | 1101101110010111 | 0010010001101000 | 0010010001101000 | 0000000000000000
1111101001010000 | 0000010110101111 | 0000010110101111 | 0000000000000000 | 1111111111111111 | 1111111111111111
0001001000110100 | 1111111111110101 | 1110110111001011 | 0001001000110100 | 1111111111110101 | 1110110111000001
(10 rows)
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 zpbit_table;
a | b | a<b | a<=b | a=b | a>=b | a>b | a<>b
------------------+------------------+-----+------+-----+------+-----+------
0000111100000000 | 0001000000000000 | t | t | f | f | f | t
0001111100000000 | 0001000100000000 | f | f | f | t | t | t
0010111100000000 | 0001001000000000 | f | f | f | t | t | t
0011111100000000 | 0001001100000000 | f | f | f | t | t | t
1000111100000000 | 0000010000000000 | f | f | f | t | t | t
0000000000001111 | 0000000000010000 | t | t | f | f | f | t
0000000100100011 | 1111111111111111 | t | t | f | f | f | t
0010010001101000 | 0010010001101000 | f | t | t | t | f | f
1111101001010000 | 0000010110101111 | f | f | f | t | t | t
0001001000110100 | 1111111111110101 | t | t | f | f | f | t
(10 rows)
SELECT a,a<<4 AS "a<<4",b,b>>2 AS "b>>2" FROM zpbit_table;
a | a<<4 | b | b>>2
------------------+------------------+------------------+------------------
0000111100000000 | 1111000000000000 | 0001000000000000 | 0000010000000000
0001111100000000 | 1111000000000000 | 0001000100000000 | 0000010001000000
0010111100000000 | 1111000000000000 | 0001001000000000 | 0000010010000000
0011111100000000 | 1111000000000000 | 0001001100000000 | 0000010011000000
1000111100000000 | 1111000000000000 | 0000010000000000 | 0000000100000000
0000000000001111 | 0000000011110000 | 0000000000010000 | 0000000000000100
0000000100100011 | 0001001000110000 | 1111111111111111 | 0011111111111111
0010010001101000 | 0100011010000000 | 0010010001101000 | 0000100100011010
1111101001010000 | 1010010100000000 | 0000010110101111 | 0000000101101011
0001001000110100 | 0010001101000000 | 1111111111110101 | 0011111111111101
(10 rows)
DROP TABLE zpbit_table;
-- The following should fail
select B'001' & B'10';
ERROR: bitand: Cannot AND bitstrings of different sizes
select B'0111' | B'011';
ERROR: bitor: Cannot OR bitstrings of different sizes
select B'0010' # B'011101';
ERROR: bitxor: Cannot XOR bitstrings of different sizes
-- More position tests, checking all the boundary cases
SELECT POSITION(B'1010' IN B'0000101'); -- 0
position
----------
0
(1 row)
SELECT POSITION(B'1010' IN B'00001010'); -- 5
position
----------
5
(1 row)
SELECT POSITION(B'1010' IN B'00000101'); -- 0
position
----------
0
(1 row)
SELECT POSITION(B'1010' IN B'000001010'); -- 6
position
----------
6
(1 row)
SELECT POSITION(B'' IN B'00001010'); -- 1
position
----------
1
(1 row)
SELECT POSITION(B'0' IN B''); -- 0
position
----------
0
(1 row)
SELECT POSITION(B'' IN B''); -- 0
position
----------
0
(1 row)
SELECT POSITION(B'101101' IN B'001011011011011000'); -- 3
position
----------
3
(1 row)
SELECT POSITION(B'10110110' IN B'001011011011010'); -- 3
position
----------
3
(1 row)
SELECT POSITION(B'1011011011011' IN B'001011011011011'); -- 3
position
----------
3
(1 row)
SELECT POSITION(B'1011011011011' IN B'00001011011011011'); -- 5
position
----------
5
(1 row)
SELECT POSITION(B'11101011' IN B'11101011'); -- 1
position
----------
1
(1 row)
SELECT POSITION(B'11101011' IN B'011101011'); -- 2
position
----------
2
(1 row)
SELECT POSITION(B'11101011' IN B'00011101011'); -- 4
position
----------
4
(1 row)
SELECT POSITION(B'11101011' IN B'0000011101011'); -- 6
position
----------
6
(1 row)
SELECT POSITION(B'111010110' IN B'111010110'); -- 1
position
----------
1
(1 row)
SELECT POSITION(B'111010110' IN B'0111010110'); -- 2
position
----------
2
(1 row)
SELECT POSITION(B'111010110' IN B'000111010110'); -- 4
position
----------
4
(1 row)
SELECT POSITION(B'111010110' IN B'00000111010110'); -- 6
position
----------
6
(1 row)
SELECT POSITION(B'111010110' IN B'11101011'); -- 0
position
----------
0
(1 row)
SELECT POSITION(B'111010110' IN B'011101011'); -- 0
position
----------
0
(1 row)
SELECT POSITION(B'111010110' IN B'00011101011'); -- 0
position
----------
0
(1 row)
SELECT POSITION(B'111010110' IN B'0000011101011'); -- 0
position
----------
0
(1 row)
SELECT POSITION(B'111010110' IN B'111010110'); -- 1
position
----------
1
(1 row)
SELECT POSITION(B'111010110' IN B'0111010110'); -- 2
position
----------
2
(1 row)
SELECT POSITION(B'111010110' IN B'000111010110'); -- 4
position
----------
4
(1 row)
SELECT POSITION(B'111010110' IN B'00000111010110'); -- 6
position
----------
6
(1 row)
SELECT POSITION(B'111010110' IN B'000001110101111101011'); -- 0
position
----------
0
(1 row)
SELECT POSITION(B'111010110' IN B'0000001110101111101011'); -- 0
position
----------
0
(1 row)
SELECT POSITION(B'111010110' IN B'000000001110101111101011'); -- 0
position
----------
0
(1 row)
SELECT POSITION(B'111010110' IN B'00000000001110101111101011'); -- 0
position
----------
0
(1 row)
SELECT POSITION(B'111010110' IN B'0000011101011111010110'); -- 14
position
----------
14
(1 row)
SELECT POSITION(B'111010110' IN B'00000011101011111010110'); -- 15
position
----------
15
(1 row)
SELECT POSITION(B'111010110' IN B'0000000011101011111010110'); -- 17
position
----------
17
(1 row)
SELECT POSITION(B'111010110' IN B'000000000011101011111010110'); -- 19
position
----------
19
(1 row)
SELECT POSITION(B'000000000011101011111010110' IN B'000000000011101011111010110'); -- 1
position
----------
1
(1 row)
SELECT POSITION(B'00000000011101011111010110' IN B'000000000011101011111010110'); -- 2
position
----------
2
(1 row)
SELECT POSITION(B'0000000000011101011111010110' IN B'000000000011101011111010110'); -- 0
position
----------
0
(1 row)
-- Shifting
CREATE TABLE ZPBIT_SHIFT_TABLE(b BIT(16));
INSERT INTO ZPBIT_SHIFT_TABLE VALUES (B'11011');
INSERT INTO ZPBIT_SHIFT_TABLE SELECT b>>1 FROM ZPBIT_SHIFT_TABLE;
INSERT INTO ZPBIT_SHIFT_TABLE SELECT b>>2 FROM ZPBIT_SHIFT_TABLE;
INSERT INTO ZPBIT_SHIFT_TABLE SELECT b>>4 FROM ZPBIT_SHIFT_TABLE;
INSERT INTO ZPBIT_SHIFT_TABLE SELECT b>>8 FROM ZPBIT_SHIFT_TABLE;
SELECT POSITION(B'1101'IN b),
POSITION(B'11011' IN b),
b
FROM ZPBIT_SHIFT_TABLE ;
position | position | b
----------+----------+------------------
1 | 1 | 1101100000000000
2 | 2 | 0110110000000000
3 | 3 | 0011011000000000
4 | 4 | 0001101100000000
5 | 5 | 0000110110000000
6 | 6 | 0000011011000000
7 | 7 | 0000001101100000
8 | 8 | 0000000110110000
9 | 9 | 0000000011011000
10 | 10 | 0000000001101100
11 | 11 | 0000000000110110
12 | 12 | 0000000000011011
13 | 0 | 0000000000001101
0 | 0 | 0000000000000110
0 | 0 | 0000000000000011
0 | 0 | 0000000000000001
(16 rows)
CREATE TABLE VARBIT_SHIFT_TABLE(v BIT VARYING(18));
INSERT INTO VARBIT_SHIFT_TABLE VALUES (B'11011');
INSERT INTO VARBIT_SHIFT_TABLE SELECT CAST(v AS BIT(6)) >>1 FROM VARBIT_SHIFT_TABLE;
INSERT INTO VARBIT_SHIFT_TABLE SELECT CAST(v AS BIT(8)) >>2 FROM VARBIT_SHIFT_TABLE;
INSERT INTO VARBIT_SHIFT_TABLE SELECT CAST(v AS BIT(12)) >>4 FROM VARBIT_SHIFT_TABLE;
INSERT INTO VARBIT_SHIFT_TABLE SELECT CAST(v AS BIT(20)) >>8 FROM VARBIT_SHIFT_TABLE;
SELECT POSITION(B'1101' IN v),
POSITION(B'11011' IN v),
v
FROM VARBIT_SHIFT_TABLE ;
position | position | v
----------+----------+--------------------
1 | 1 | 11011
2 | 2 | 011011
3 | 3 | 00110110
4 | 4 | 00011011
5 | 5 | 000011011000
6 | 6 | 000001101100
7 | 7 | 000000110110
8 | 8 | 000000011011
9 | 9 | 000000001101100000
10 | 10 | 000000000110110000
11 | 11 | 000000000011011000
12 | 12 | 000000000001101100
13 | 13 | 000000000000110110
14 | 14 | 000000000000011011
15 | 0 | 000000000000001101
0 | 0 | 000000000000000110
(16 rows)
DROP TABLE ZPBIT_SHIFT_TABLE;
DROP TABLE VARBIT_SHIFT_TABLE;
src/test/regress/parallel_schedule
View file @
f31844f1
# ----------
# The first group of parallel test
# ----------
test: boolean char name varchar text int2 int4 int8 oid float4 float8 numeric
test: boolean char name varchar text int2 int4 int8 oid float4 float8
bit
numeric
# Depends on things setup during char, varchar and text
test: strings
...
...
src/test/regress/serial_schedule
View file @
f31844f1
# $Header: /cvsroot/pgsql/src/test/regress/serial_schedule,v 1.
2 2000/10/01 21:19:09
petere Exp $
# $Header: /cvsroot/pgsql/src/test/regress/serial_schedule,v 1.
3 2000/11/22 13:37:44
petere Exp $
# This should probably be in an order similar to parallel_schedule.
test: boolean
test: char
...
...
@@ -11,6 +11,7 @@ test: int8
test: oid
test: float4
test: float8
test: bit
test: numeric
test: strings
test: numerology
...
...
src/test/regress/sql/bit.sql
0 → 100644
View file @
f31844f1
--
-- BIT types
--
--
-- Build tables for testing
--
CREATE
TABLE
ZPBIT_TABLE
(
b
BIT
(
11
));
INSERT
INTO
ZPBIT_TABLE
VALUES
(
B
''
);
INSERT
INTO
ZPBIT_TABLE
VALUES
(
B
'0'
);
INSERT
INTO
ZPBIT_TABLE
VALUES
(
B
'11011'
);
INSERT
INTO
ZPBIT_TABLE
VALUES
(
B
'01010101010'
);
INSERT
INTO
ZPBIT_TABLE
VALUES
(
B
'101011111010'
);
-- too long
--INSERT INTO ZPBIT_TABLE VALUES ('X554');
--INSERT INTO ZPBIT_TABLE VALUES ('X555');
SELECT
*
FROM
ZPBIT_TABLE
;
CREATE
TABLE
VARBIT_TABLE
(
v
BIT
VARYING
(
11
));
INSERT
INTO
VARBIT_TABLE
VALUES
(
B
''
);
INSERT
INTO
VARBIT_TABLE
VALUES
(
B
'0'
);
INSERT
INTO
VARBIT_TABLE
VALUES
(
B
'010101'
);
INSERT
INTO
VARBIT_TABLE
VALUES
(
B
'01010101010'
);
INSERT
INTO
VARBIT_TABLE
VALUES
(
B
'101011111010'
);
-- too long
--INSERT INTO VARBIT_TABLE VALUES ('X554');
--INSERT INTO VARBIT_TABLE VALUES ('X555');
SELECT
*
FROM
VARBIT_TABLE
;
-- Concatenation
SELECT
v
,
b
,
(
v
||
b
)
AS
concat
FROM
ZPBIT_TABLE
,
VARBIT_TABLE
ORDER
BY
3
;
-- Length
SELECT
b
,
length
(
b
)
AS
lb
FROM
ZPBIT_TABLE
;
SELECT
v
,
length
(
v
)
AS
lv
FROM
VARBIT_TABLE
;
-- 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
ZPBIT_TABLE
;
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
;
--- Bit operations
DROP
TABLE
varbit_table
;
CREATE
TABLE
varbit_table
(
a
BIT
VARYING
(
16
),
b
BIT
VARYING
(
16
));
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
\
.
SELECT
a
,
b
,
~
a
AS
"~ a"
,
a
&
b
AS
"a & b"
,
a
|
b
AS
"a | b"
,
a
#
b
AS
"a # b"
FROM
varbit_table
;
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
;
SELECT
a
,
a
<<
4
AS
"a<<4"
,
b
,
b
>>
2
AS
"b>>2"
FROM
varbit_table
;
DROP
TABLE
varbit_table
;
--- Bit operations
DROP
TABLE
zpbit_table
;
CREATE
TABLE
zpbit_table
(
a
BIT
(
16
),
b
BIT
(
16
));
COPY
zpbit_table
FROM
stdin
;
X0F
X10
X1F
X11
X2F
X12
X3F
X13
X8F
X04
X000F
X0010
X0123
XFFFF
X2468
X2468
XFA50
X05AF
X1234
XFFF5
\
.
SELECT
a
,
b
,
~
a
AS
"~ a"
,
a
&
b
AS
"a & b"
,
a
|
b
AS
"a | b"
,
a
#
b
AS
"a # b"
FROM
zpbit_table
;
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
zpbit_table
;
SELECT
a
,
a
<<
4
AS
"a<<4"
,
b
,
b
>>
2
AS
"b>>2"
FROM
zpbit_table
;
DROP
TABLE
zpbit_table
;
-- The following should fail
select
B
'001'
&
B
'10'
;
select
B
'0111'
|
B
'011'
;
select
B
'0010'
#
B
'011101'
;
-- More position tests, checking all the boundary cases
SELECT
POSITION
(
B
'1010'
IN
B
'0000101'
);
-- 0
SELECT
POSITION
(
B
'1010'
IN
B
'00001010'
);
-- 5
SELECT
POSITION
(
B
'1010'
IN
B
'00000101'
);
-- 0
SELECT
POSITION
(
B
'1010'
IN
B
'000001010'
);
-- 6
SELECT
POSITION
(
B
''
IN
B
'00001010'
);
-- 1
SELECT
POSITION
(
B
'0'
IN
B
''
);
-- 0
SELECT
POSITION
(
B
''
IN
B
''
);
-- 0
SELECT
POSITION
(
B
'101101'
IN
B
'001011011011011000'
);
-- 3
SELECT
POSITION
(
B
'10110110'
IN
B
'001011011011010'
);
-- 3
SELECT
POSITION
(
B
'1011011011011'
IN
B
'001011011011011'
);
-- 3
SELECT
POSITION
(
B
'1011011011011'
IN
B
'00001011011011011'
);
-- 5
SELECT
POSITION
(
B
'11101011'
IN
B
'11101011'
);
-- 1
SELECT
POSITION
(
B
'11101011'
IN
B
'011101011'
);
-- 2
SELECT
POSITION
(
B
'11101011'
IN
B
'00011101011'
);
-- 4
SELECT
POSITION
(
B
'11101011'
IN
B
'0000011101011'
);
-- 6
SELECT
POSITION
(
B
'111010110'
IN
B
'111010110'
);
-- 1
SELECT
POSITION
(
B
'111010110'
IN
B
'0111010110'
);
-- 2
SELECT
POSITION
(
B
'111010110'
IN
B
'000111010110'
);
-- 4
SELECT
POSITION
(
B
'111010110'
IN
B
'00000111010110'
);
-- 6
SELECT
POSITION
(
B
'111010110'
IN
B
'11101011'
);
-- 0
SELECT
POSITION
(
B
'111010110'
IN
B
'011101011'
);
-- 0
SELECT
POSITION
(
B
'111010110'
IN
B
'00011101011'
);
-- 0
SELECT
POSITION
(
B
'111010110'
IN
B
'0000011101011'
);
-- 0
SELECT
POSITION
(
B
'111010110'
IN
B
'111010110'
);
-- 1
SELECT
POSITION
(
B
'111010110'
IN
B
'0111010110'
);
-- 2
SELECT
POSITION
(
B
'111010110'
IN
B
'000111010110'
);
-- 4
SELECT
POSITION
(
B
'111010110'
IN
B
'00000111010110'
);
-- 6
SELECT
POSITION
(
B
'111010110'
IN
B
'000001110101111101011'
);
-- 0
SELECT
POSITION
(
B
'111010110'
IN
B
'0000001110101111101011'
);
-- 0
SELECT
POSITION
(
B
'111010110'
IN
B
'000000001110101111101011'
);
-- 0
SELECT
POSITION
(
B
'111010110'
IN
B
'00000000001110101111101011'
);
-- 0
SELECT
POSITION
(
B
'111010110'
IN
B
'0000011101011111010110'
);
-- 14
SELECT
POSITION
(
B
'111010110'
IN
B
'00000011101011111010110'
);
-- 15
SELECT
POSITION
(
B
'111010110'
IN
B
'0000000011101011111010110'
);
-- 17
SELECT
POSITION
(
B
'111010110'
IN
B
'000000000011101011111010110'
);
-- 19
SELECT
POSITION
(
B
'000000000011101011111010110'
IN
B
'000000000011101011111010110'
);
-- 1
SELECT
POSITION
(
B
'00000000011101011111010110'
IN
B
'000000000011101011111010110'
);
-- 2
SELECT
POSITION
(
B
'0000000000011101011111010110'
IN
B
'000000000011101011111010110'
);
-- 0
-- Shifting
CREATE
TABLE
ZPBIT_SHIFT_TABLE
(
b
BIT
(
16
));
INSERT
INTO
ZPBIT_SHIFT_TABLE
VALUES
(
B
'11011'
);
INSERT
INTO
ZPBIT_SHIFT_TABLE
SELECT
b
>>
1
FROM
ZPBIT_SHIFT_TABLE
;
INSERT
INTO
ZPBIT_SHIFT_TABLE
SELECT
b
>>
2
FROM
ZPBIT_SHIFT_TABLE
;
INSERT
INTO
ZPBIT_SHIFT_TABLE
SELECT
b
>>
4
FROM
ZPBIT_SHIFT_TABLE
;
INSERT
INTO
ZPBIT_SHIFT_TABLE
SELECT
b
>>
8
FROM
ZPBIT_SHIFT_TABLE
;
SELECT
POSITION
(
B
'1101'
IN
b
),
POSITION
(
B
'11011'
IN
b
),
b
FROM
ZPBIT_SHIFT_TABLE
;
CREATE
TABLE
VARBIT_SHIFT_TABLE
(
v
BIT
VARYING
(
18
));
INSERT
INTO
VARBIT_SHIFT_TABLE
VALUES
(
B
'11011'
);
INSERT
INTO
VARBIT_SHIFT_TABLE
SELECT
CAST
(
v
AS
BIT
(
6
))
>>
1
FROM
VARBIT_SHIFT_TABLE
;
INSERT
INTO
VARBIT_SHIFT_TABLE
SELECT
CAST
(
v
AS
BIT
(
8
))
>>
2
FROM
VARBIT_SHIFT_TABLE
;
INSERT
INTO
VARBIT_SHIFT_TABLE
SELECT
CAST
(
v
AS
BIT
(
12
))
>>
4
FROM
VARBIT_SHIFT_TABLE
;
INSERT
INTO
VARBIT_SHIFT_TABLE
SELECT
CAST
(
v
AS
BIT
(
20
))
>>
8
FROM
VARBIT_SHIFT_TABLE
;
SELECT
POSITION
(
B
'1101'
IN
v
),
POSITION
(
B
'11011'
IN
v
),
v
FROM
VARBIT_SHIFT_TABLE
;
DROP
TABLE
ZPBIT_SHIFT_TABLE
;
DROP
TABLE
VARBIT_SHIFT_TABLE
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment