OceanBase Database allows you to create a roaring bitmap column by using the CREATE TABLE or ALTER TABLE statement.
Considerations
- To view the query results in a visualized way, add the
--binary-as-hexparameter when you connect to the client to convert the binary results to hexadecimal.
Examples
You can create a table with a roaring bitmap column by using the CREATE TABLE statement. Here is an example:
CREATE TABLE t1 (rb ROARINGBITMAP);
You can add or drop a roaring bitmap column from an existing table by using the ALTER TABLE statement. Here is an example:
ALTER TABLE t1 ADD COLUMN rb2 ROARINGBITMAP;
ALTER TABLE t1 DROP COLUMN rb2;
You can set a default value for a roaring bitmap column. Here is an example:
ALTER TABLE t1 MODIFY COLUMN rb ROARINGBITMAP DEFAULT x'0100';
Here are some examples of writing and querying data in a roaring bitmap column:
// Create a test table.
obclient> CREATE TABLE t2 (
rb ROARINGBITMAP
);
DESC t2;
// Insert test data.
obclient> INSERT INTO t2 VALUES (rb_from_string('1,2,3'));
INSERT INTO t2 VALUES (x'0100');
// Query the test table.
obclient> SELECT * FROM t2;
The return result is as follows:
+----------------------------------+
| rb |
+----------------------------------+
| 0x010303010000000200000003000000 |
| 0x0100 |
+----------------------------------+
2 rows in set
