Duration Data Type in Cassandra
Duration data type in Cassandra is used to store a duration value with nanosecond precision. When you need to store Duration, you will be using format Quantity+Unit. Below is the list of Units
y: years
mo: months
w: weeks
d: days
h: hours
m: minutes
s: seconds
ms: milliseconds
us or µs : microseconds
ns: nanoseconds
Let's say that If I have to save 12 hours 57 minutes and 43 seconds then I will write like 12h57m43s.
In below example, I am going to create the tbs table with column durationcolumn of data type duration and insert couple of records.
CQLSH:techbrotherstutorials>CREATE TABLE techbrotherstutorials.tbs
(
id INT PRIMARY KEY,
durationcolumn DURATION,
NAME TEXT
);
(
id INT PRIMARY KEY,
durationcolumn DURATION,
NAME TEXT
);
Insert couple of recrods in table by using below CQL scripts
CQLSH:techbrotherstutorials>INSERT INTO tbs
(
id,
durationcolumn,
NAME
)
VALUES
(
1,
12h57m43s,
'Doe John'
);
(
id,
durationcolumn,
NAME
)
VALUES
(
1,
12h57m43s,
'Doe John'
);
CQLSH:techbrotherstutorials>INSERT INTO tbs
(
id,
durationcolumn,
NAME
)
VALUES
(
2,
10y11mo24d9h23m34s45ms100us123ns,
'Mike'
);
(
id,
durationcolumn,
NAME
)
VALUES
(
2,
10y11mo24d9h23m34s45ms100us123ns,
'Mike'
);
Check the data by using CQL Select statement
CQLSH:techbrotherstutorials>SELECT *
FROM tbs;
FROM tbs;