Search code examples
scriptingcassandracqldml

How to reuse uuid in cql script


Given the following tables:

CREATE TABLE videos (
    video_id UUID,
    added_date TIMESTAMP,
    description TEXT,
    title TEXT,
    user_id UUID,
    PRIMARY KEY (video_id)
);

CREATE TABLE videos_by_title_year (
    title TEXT,
    added_year INT,
    added_date TIMESTAMP,
    description TEXT,
    user_id UUID,
    video_id UUID,
    PRIMARY KEY ((title, added_year))
);

When a new video is created it has to be added to these two tables. The video_idneeds to be the same in both. On the application side you would solve this programmatically.

I'm writing some cql dml scripts for test environment setup data. So basically a long list of INSERT statements.

INSERT (video_id, ... , user_id) INTO videos VALUES (uuid(), ...);
INSERT (title, ... , video_id) INTO videos_by_title_year VALUES ('Forrest Gump', ... , uuid());

In this case the video_id's will be different. Can I in someway reuse a generated UUID in cql scripts? Or is the only possible solution to set the id's by hand in my script like below?

INSERT (video_id, ... , user_id) INTO videos VALUES (7bd6e4ae-0ef2-11e5-9de3-8438355b7e3a, ...);
INSERT (title, ... , video_id) INTO videos_by_title_year VALUES ('Forrest Gump', ... , 7bd6e4ae-0ef2-11e5-9de3-8438355b7e3a);

Solution

  • As far as I know now this is not possible.