1
votes

I'm considering migrating some PostgreSQL databases to CockroachDB. One application I have uses the PostgreSQL hstore datatype.

Is there an equivalent way to store this data in CockroachDB?

If not, what is the best-practice for mapping this datatype with as little change to the application code as possible?

1

1 Answers

1
votes

CockroachDB has a jsonb type that is quite similar to PostgreSQL's so you could convert your hstores to jsonb objects (i.e. an hstore like 'a=>x, b=>y' would become {"a":"x", "b":"y"} on jsonb).

The most common (probably) operator you'd be using with hstore would be -> to access a value based on a key. With jsonb, -> gives you a jsonb result so you'd want to switch to ->> which gives you a string (just like -> with hstore). The @> operator behaves similarly with jsonb (both CockroachDB's and PostgreSQL's) as it does with hstore but some changes would be needed. Any hstore_... functions would, of course, need to be replaced.

CockroachDB's jsonb is very similar to PostgreSQL's. Also, hstore is sort of deprecated in favor of jsonb in PostgreSQL. So you might want to replace hstore with jsonb inside PostgreSQL before trying to move to CockroachDB.