I have a table of accounts which generates unique keys with a sequence. It is used to generate unique identities for accounts and account/user pairs.
I tried the following from pgsql:
CREATE INDEX ON accounts (account_id, user_id) WHERE user_id IS NULL;
and
CREATE UNIQUE INDEX ON accounts (account_id, COALESCE(user_id, ''));
But both cases are not supported in cockroach.
Is there another way of ensuring uniqueness with NULL values?
I also have a different UNIQUE index on user_id
to allow unique IDs to be generated for users without an account.
You may be able to do something like create a computed column and then use that in an index: