Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save WesleyBatista/6516f6941e76c1ce9f5138b437e0afb7 to your computer and use it in GitHub Desktop.
Save WesleyBatista/6516f6941e76c1ce9f5138b437e0afb7 to your computer and use it in GitHub Desktop.
Cockroach Bigserial and Bigint compatibility - Quick Study

Is the bigserial compatible with the bigint on Cockroach?

Create the tables

Let's create table_x with a bigserial column and set it as the primary key.

CREATE TABLE table_x (
	id bigserial PRIMARY KEY, 
	whatever text
);

Now we create the table_y but set it's columns to bigint, but no primary key this time (this should not interfere in anything):

CREATE TABLE table_y (
	table_x_id bigint,
	whatever text
);

load data

Let's insert some data on the tables and try to compare the values:

INSERT INTO table_x(id, whatever) values (1000000000009, 'name 1'), (200000000000000009, 'name 2');
INSERT INTO table_y(id, whatever) values (1000000000009, 'name 1'), (200000000000000009, 'name 2');

Compare the values

select
	id,
	table_x.whatever as whatever,
	(table_x.id = table_y.table_x_id) as is_equal
from
	table_x as table_x

left join table_y as table_y
on table_y.table_x_id = table_x.id

Result

          id         | whatever | is_equal  
+--------------------+----------+----------+
       1000000000009 | name 1   |   true    
  200000000000000009 | name 2   |   true    
(2 rows)

Time: 4.427524ms

Conclusion

I guess it is safe to say that for LEFT JOINs (and probably the other JOINs as well) both types are compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment