sqlgg icon indicating copy to clipboard operation
sqlgg copied to clipboard

Add JOIN statement tests

Open jongleb opened this issue 1 year ago • 2 comments

These test shows required improvements to make JOINS work properly.

When dealing with a LEFT JOIN, nullability arises under the following scenarios:

  1. No Foreign Key:

    • If there is no foreign key relationship between the tables involved in the LEFT JOIN, nullability can occur when there is no matching record in the right table. In this case, all fields from the right table will be NULL.
  2. Nullable Foreign Key:

    • Nullability may also arise when there is a nullable foreign key, and there is no matching record in the right table. If the foreign key in the left table allows NULL values, fields from the right table will be NULL in case of no match.

These scenarios highlight the conditions under which NULL values may appear in the result set of a LEFT JOIN operation.

jongleb avatar Dec 13 '23 11:12 jongleb

  • for the first case the reason is in https://github.com/ygrek/sqlgg/blob/null/lib/syntax.ml#L330 (it works with just type_name without referencing table)
  • for the second case it mentions ON DELETE CASCADE in description, but not in the test

overall FOREIGN KEY was not handled until now at all, so thanks for bringing this up, but please uncomment the test cases so that they are actually failing

ygrek avatar Dec 27 '23 21:12 ygrek

lease uncomment the test cases so that they are actually failing

Done.

for the second case it mentions ON DELETE CASCADE in description, but not in the

I removed this option, thanks, I found out that nullability on JOIN depends only on the column nullability and on the reference existence

jongleb avatar Dec 29 '23 10:12 jongleb