Create a blob column

A blob (Binary Large OBject) data type represents a constant hexadecimal number defined as 0[xX](hex)+ where hex is a hexadecimal character, such as [0-9a-fA-F]. For example, 0xcafe. The maximum theoretical size for a blob is 2 GB. The practical limit on blob size, however, is less than 1 MB. A blob type is suitable for storing a small image or short string.

Blob conversion functions

These functions convert a native type into binary data (blob), and convert a blob back into a native type:

  • typeAsBlob(value)

  • blobAsType(value)

For every native non-blob data type supported by CQL, the typeAsBlob function takes an argument of that data type and returns it as a blob.

Conversely, the blobAsType function takes a 64-bit blob argument and converts it to a value of the specified data type, if possible.

The following example shows the use of a blob column and the bigintAsBlob function:

Create a table with a blob column:

CREATE TABLE IF NOT EXISTS cycling.lastname_bio (
  lastname varchar PRIMARY KEY,
  bio blob
);

Insert data into the table:

INSERT INTO cycling.lastname_bio (
  lastname, bio
) VALUES (
  'TSATEVICH', bigintAsBlob(3)
);

Query the table:

SELECT * FROM cycling.lastname_bio;
Results
 lastname  | bio
-----------+--------------------
 TSATEVICH | 0x0000000000000003

(1 rows)

 lastname  | bio
-----------+--------------------
 TSATEVICH | 0x0000000000000003

(1 rows)

The following example shows the use of blobAsBigint function. Alter the table to add a bigint column:

ALTER TABLE cycling.lastname_bio
  ADD id bigint;

Insert additional data into the table:

INSERT INTO cycling.lastname_bio (
  lastname, id
) VALUES (
  'DUVAL', blobAsBigint(0x0000000000000003)
);

Query the table:

SELECT * FROM cycling.lastname_bio;
Results
SELECT * FROM cycling.lastname_bio;

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com