• Industrial Automation Engineer (unregistered)

    A few thousand dollars? I won't even set my alarm clock for that pittance.

  • (nodebb)

    Most Java logging libraries accept an optional exception as first or last parameter and print it's stack trace if given, so some version of logger.warn("cross join", new Exception()) would have done the trick

  • xorium (unregistered)

    Looking at the horrendous placement of the curly braces, I suppose the developer was quite new to java.

  • Watts (unregistered)

    I'm not familiar with what I assume is the DB2 SQL dialect, but with SQL I've worked with in the past, a comma means an inner join, which would imply that this code is also changing the meaning of the query, right?

  • (nodebb) in reply to Watts

    It's a cross join by default, it becomes an inner join if you include the joining condition in the WHERE clause.

  • (nodebb) in reply to Watts

    a comma means an inner join

    A comma does not mean an inner join. A comma in the from clause means another table is involved. If there is no matching condition in the where clause, then this results in a cross join. If the where clause has an equality condition that compares columns from the two tables, then it results in an inner join.

    If the where clause has the SQL Server specific "table1.column *= table2.column" syntax, then this is an outer join. This syntax was deprecated 25 years ago and stops working if the database in in SQL 2012 or higher compatibility mode. I believe it still work on the current version of SQL Server if the database in in an old enough compatibility mode.

    Addendum 2025-01-09 10:14: I would also add that if you still do this in 2025, you are a bad person.

  • Daniel (unregistered)

    Bonus points to not call the base implementation to return the cross join operator but to know it better... Yes: Chance that the actual implementation uses a different character is probably small. But we've been bitten before by SQL

  • Joe (unregistered) in reply to Jaime

    While this comma-for-joins syntax may still run and return data, as you pointed out, it was deprecated 25 years ago, and I remember over 20 years ago running into an example of a query like this that returned the wrong data. It's not supported, and anyone that uses it will get data to return but in my experience there's a small chance it might not be the correct data. Besides, the (not so) new syntax is so much easier for us mere humans to read when compared to that old syntax, so I don't know why anyone would want to still use it.

  • (nodebb)

    Maybe I'm reading to much into this, but wouldn't it be better to return the result of the base method instead of a string literal? Not that I want to give any credit to the rest of the implementation.

  • (nodebb)

    If the goal is to both log the use of cross join and prevent an actual cross join from propagating into the final query then the base method's return value must be replaced by something "safe". Regardless of what damage that does to correctness.

    If the goal is only to log, then yes, return the base method's value.

  • OM222O (unregistered)
    Comment held for moderation.
  • (nodebb) in reply to Joe

    While this comma-for-joins syntax may still run and return data, as you pointed out, it was deprecated 25 years ago, and I remember over 20 years ago running into an example of a query like this that returned the wrong data.

    The new join ("ansi-joins") syntax was added in ANSI SQL-92, so it's approximately 33 years new. The old join ("comma-for-joins") syntax is not deprecated, it is still (and probably will always remain) part of the ANSI SQL standard. Note that in this old syntax, an outer join does not exist in the standard. Every database engine uses/used their own version: sql server used *, oracle used (+), etc. The outer join syntax may be deprecated in some databases.

    If the old join syntax returned wrong data, there was an either an error in the sql engine (very unlikely) or in your query (much more likely).

Leave a comment on “Crossly Joined”

Log In or post as a guest

Replying to comment #:

« Return to Article