Hi,

On Thursday, April 28, 2016 at 11:59:22 PM UTC+2, Rich Rauenzahn wrote:
>
> This is apparently an expected (and standardized) thing in SQL that ('A', 
> 'B', NULL) is unique to ('A', 'B', NULL) as NULL is never equal to another 
> NULL.
>

Yes, though the standard goes even further: every comparision with NULL 
results in false, in that sense NULL is never equal to NULL but also never 
unequal to NULL.
 

> There is a workaround at the SQL level of ... 
>
> CREATE UNIQUE INDEX ab_c_null_idx ON my_table (id_A, id_B) WHERE id_C IS NULL;
>
>
This only creates an index on two columns though, you might still be 
interested in indexing the cases where A, B, C are not null…
 

> I'm wondering if this ought to at least be addressed in a runtime warning,
>

Runtime warnings are the worst imo, if at all a system check.
 

> or at least documentation in unique_together -- and I'm hoping that 
> perhaps a Django level workaround could be devised to explicitly ask for 
> unique indexes accommodating null values.
>

I am not against a note in the docs, but I find the fact that nulls are not 
"unique" and can exist in an index more than once very useful (fwiw 
ordering after a column with null can also be interesting across 
databases). I'd be interested to hear about your use case -- the "general" 
use case is usually that you have an optional column but want to ensure it 
is unique as soon as it is filled…

Cheers,
Florian

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/f4c479dc-4aef-4a92-9d5b-16edbe23c23e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to