Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
Last active Feb 26, 2021
Embed
What would you like to do?
You shouldn't be using USING
db=> create table a (x int);
CREATE TABLE
db=> create table b (x int, y int);
CREATE TABLE
db=> create table c (y int, z int);
CREATE TABLE

db=> select * from a join b using (x) join c using (y);
 y | x | z
---+---+---
(0 rows)

-- query works fine

-- now let's introduce a column seemingly unrelated to query
db=> alter table a add column y int;
ALTER TABLE
db=> select * from a join b using (x) join c using (y);
ERROR:  common column name "y" appears more than once in left table

-- ouch

db=> select * from a join b on a.x=b.x join c on b.y=c.y;
 x | y | x | y | y | z
---+---+---+---+---+---
(0 rows)

-- using ON explicitly avoids the issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment