简体   繁体   中英

SQL error when trying to use GENERATED BY DEFAULT AS IDENTITY in CockroachDb

I'm trying to create a simple table auto auto-generated identity key, but Cockroachdb is throwing a syntax error for the keyword GENERATED . Is there something I'm missing?

CREATE TABLE IF NOT EXISTS "users"
(
    "id" bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL,
    "age" bigint NOT NULL, 
    "name" varchar NOT NULL DEFAULT '', 
    "email" varchar NOT NULL, 
    PRIMARY KEY("id")
);

You may want to use unique_rowid instead. It is time-ordered. I have used it successfully for a streaming data ingest application.

If your application performs a lot of concurrent inserts, you could potentially use uuid_v4 . It is unordered, but it doesn't slow down inserts on concurrent connections.

CockroachDB appears to use SERIAL for this purpose:

"id" serial8 primary key,

Note that because Cockroach is a distributed databases, this introduces contention and SERIAL is not recommended for assigning unique ids to rows.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM