Fork me on GitHub
#sql
<
2020-10-13
>
seancorfield19:10:44

Does anyone using JOIN USING (cols) ? I didn't even realize it was a thing until yesterday 😐

9
3
Charles Fourdrignier12:10:09

Same here. I learn this, like 6 months ago.

iarenaza15:10:25

We sometimes do, although sparingly.

dharrigan20:10:23

Sometimes, although not in my Clojure code atm

isak20:10:54

I can't, I think you'd need a DB that used full length primary key names for that to be useful. E.g., your "projects" table having a primary key of "project_id" instead of "id"

dharrigan20:10:22

It doesn't have to be a primary key - can be any column where the names (and type!) are the same

isak20:10:01

Yea, I understand, but I figured primary keys and foreign keys be the main use case

dominicm20:10:37

We have a lot of joins which could use that, although we don't right now. We have multiple keys from different places, so joining them up like that is natural.

seancorfield20:10:16

Apparently HoneySQL 1.0 supports this (I just found some tests for it) so now I have to make HoneySQL 2.0 support it 😐

seancorfield20:10:16

I don't think we have a single JOIN anywhere in our codebase where the column names are identical... it's nearly always on sometable.id = thistable.sometable_id

hiredman21:10:48

I do sometimes wish we used sometable_id as the column name even in sometable, having columns named 'id' can result in some ambiguous keys in maps (didn't know about USING either)

seancorfield21:10:54

Yeah, there's definitely some pros to consistently using <table>_id even for the PK of <table>...