CREATE TABLE foo (x INT);
INSERT INTO foo VALUeS (1);
CREATE TABLE bar (x FLOAT);
INSERT INTO bar VALUES (1);
SELECT pg_typeof(x) FROM foo JOIN bar USING (x);
The type of x is is double, - because x was implicitly upcast as we can see with EXPLAIN: Merge Join (cost=338.29..931.54 rows=28815 width=4)
Merge Cond: (bar.x = ((foo.x)::double precision))
Arguably, you should never be joining on keys of different types. It just bad design. But you don't always get that choice if someone else made the data model for you. CREATE TABLE foo (x INT);
INSERT INTO foo VALUeS (1);
CREATE TABLE bar (x INT);
INSERT INTO bar VALUES (1);
CREATE TABLE baz (x INT);
INSERT INTO baz VALUES (1);
SELECT \*
FROM foo
JOIN bar USING (x)
JOIN baz USING (x);
Which might not be what you expected :-) CREATE TABLE foo (x INT);
CREATE TABLE bar (x INT);
SELECT \* FROM foo JOIN bar USING (x);
There is only one `x` in the above `SELECT *` - the automatically disambiguated one. Which is typically want you want.
Thanks for letting me know - you can stare yourself blind on that stuff