February 2020
Intermediate to advanced
734 pages
38h 13m
English
If we wanted to use our new ID generator in a table, then we could do it very simply. Assuming that we already have our myapp.msg_log table, we could create a new table based on it with the following SQL statement:
CREATE SCHEMA myapp1;
CREATE TABLE myapp1.msg_log (
LIKE myapp.msg_log INCLUDING INDEXES
);
ALTER TABLE myapp1.msg_log
ALTER id TYPE BIGINT,
ALTER id SET DEFAULT shard.next_unique_id(1);
This structure would correspond with shard number 1. All we need to do is modify the id column so that it can store our 64-bit integer and then set the default value to invoke our next_unique_id function. By doing so, we can create up to 2,048 schemas holding tables like this, and every generated ID will be unique across all of ...
Read now
Unlock full access