Skip to content

Support "NULLS" clause in createIndex #1470

Description

@jonahkagan

Description

There are a few different clauses to control the behavior of NULL in indexes. From the docs:

NULLS FIRST
Specifies that nulls sort before non-nulls. This is the default when DESC is specified.

NULLS LAST
Specifies that nulls sort after non-nulls. This is the default when DESC is not specified.

NULLS DISTINCT
NULLS NOT DISTINCT
Specifies whether for a unique index, null values should be considered distinct (not equal). The default is that they are distinct, so that a unique index could contain multiple null values in a column.

It would be great if createIndex supported specifying one of these options. I'm particularly interested in NULLS NOT DISTINCT for my use case, but I think they are likely all useful to someone!

I'd be happy to contribute a pull request to implement this if you'd like!

Suggested solution

A proposal for the API: Add a new field nulls to the options parameter of createIndex. The field would have type: 'first' | 'last' | 'distinct' | 'not distinct'.

Alternative

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

c: featureRequest for new feature

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions