| ▲ | n4r9 2 hours ago | |||||||
I've used SQL for around a decade and also never came across it. I'm maintaining SQL code with hundreds if not thousands of basic primary key joins and this could make those queries way more concise. Now I want to know the reasons for not using USING! | ||||||||
| ▲ | tkejser 2 hours ago | parent [-] | |||||||
There are reasons for not USING. First, you need to be aware of the implicit disambiguration. When you join with USING, you are introducing a hidden column that represents both sides. This is typically what you want - but it can bite you. Consider this PostgreSQL example:
The type of x is is double, - because x was implicitly upcast as we can see with EXPLAIN:
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.It also means that this actually works:
Which might not be what you expected :-)If you are both the data modeller and the query writer - I have not been able to come up with a reason for not USING. | ||||||||
| ||||||||