Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Indexes? #585

Closed
Togrias opened this issue Jun 19, 2019 · 0 comments · Fixed by #1763
Closed

Partial Indexes? #585

Togrias opened this issue Jun 19, 2019 · 0 comments · Fixed by #1763

Comments

@Togrias
Copy link

Togrias commented Jun 19, 2019

Exposed currently has no way to define partial indexes.

E.g:

CREATE UNIQUE INDEX my_index
    ON table (column_a, column_b)
 WHERE column_a IS NOT NULL

Use case:
Let's say I have a database of PEOPLE. Each member of PEOPLE has a "name" (text), as well as an optional reference to PEOPLE (i.e. "parent"). But I want to make sure that for each member of PEOPLE, if it has "children", each child must have a unique name. One way to implement this is to have (proposed syntax):

uniqueIndex(name, parent_id)
partialUniqueIndex(name).where { parent_id.isNull() }

Partial Indexes are supported by Postgresql and Sqlite, but I don't think Mysql has it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants