Database Reference
In-Depth Information
# Use the UDT in a table in a map
CREATE TABLE users ( user_id int PRIMARY KEY, name varchar,
age int, addresses map <text, frozen<address>> );
# Insert some records
INSERT INTO users (user_id, name, age, addresses ) VALUES (
1, 'Willy Wonka', 42, {'office': {address: 'The Choco
Factory', country: 'US', postal_code: '123', preference:
1}, 'home': {address: 'NA'}} );
SELECT * FROM users;
user_id | age | name | addresses
----------+-----+-------------+--------------------------
1 | 42 | Willy Wonka | {
'home': {
address: 'NA',
country: null,
postal_code: null,
preference: null
},
'office': {
address: 'The Choco
Factory',
country: 'US',
postal_code: '123',
preference: 1
}
}
(1 rows)
A couple of things worth noticing:
• The UDT does not require all fields to be filled. The fields that are left unassigned
will be set to null .
• UDTs, as of Cassandra 2.1, have to be defined as frozen as they are serialized
and crammed into one cell. One may argue that frozen is just extraneous, but
Search WWH ::




Custom Search