#35329: Bug UniqueConstraint with condition and nulls-distinct
-------------------------------------+-------------------------------------
Reporter: lsaunitti | Owner: (none)
Type: Bug | Status: new
Component: Error | Version: 5.0
reporting | Keywords: nulls-distinct,
Severity: Normal | condition, UniqueConstrain
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hi, I`m Lucas (https://github.com/lsaunitti)
I found a bug when set a UniqueConstrain using condition using
nulls_distinct using like that:
Screenshot 2024-03-25 at 10.47.59.png
When django generate SQL to create a check constraint the result is "...
WHERE <condition> NULLS NOT DISTINCT".
It raise an exception on Postgresql.
To fix it, I suggest change the file django/db/backends/base/schema.py on
line 132:
Today:
sql_create_unique_index = (
"CREATE UNIQUE INDEX %(name)s ON %(table)s "
"(%(columns)s)%(include)s%(condition)s%(nulls_distinct)s"
)
To:
sql_create_unique_index = (
"CREATE UNIQUE INDEX %(name)s ON %(table)s "
"(%(columns)s)%(include)s%(nulls_distinct)s%(condition)s"
)
Regards,
Lucas Lemke Saunitti
Software Engineer
--
Ticket URL: <https://code.djangoproject.com/ticket/35329>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018e770c039a-b8d8b3c1-60f7-41a7-9962-6eaf55c8213f-000000%40eu-central-1.amazonses.com.