Structured Query with an Optional #326
-
|
If I leave out this optional Category in my ItemPropertyRow struct, my structured query works great and gives me exactly what I want for my ItemPropertyRow without my attempt on the leftJoin. However, if I want to include that optional category if it exists, because the Item which has an optional categoryID that joins to my Category table , it fails with the error: Can anyone help me with this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
I am able tp get what I need by doing this for the left join because an id can never be -1 Is there a better way to write this? It seem kind of hacky to me. |
Beta Was this translation helpful? Give feedback.
Hi @StewartLynch, this is an example where Swift's optional promotion cannot work, and so you are forced to deal with how to compare an optional and non-optional thing. And further, SQL has a 3-valued logic system (true, false, NULL), and in that system nothing is equal to NULL, even NULL itself. That can make things confusing, but what it means in practice is that when comparing things that can be NULL, you should use the "IS" operator instead of "=":