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
);
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');
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
I guess it is safe to say that for LEFT JOINs (and probably the other JOINs as well) both types are compatible.