-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
Add support for NULLS NOT DISTINCT clause #532
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @rstular, thanks for contributing!!
I think we miss a edge case (this should be added as test case):
assert_eq!(
Table::create()
.table(Glyph::Table)
.col(ColumnDef::new(Glyph::Image).json())
.col(ColumnDef::new(Glyph::Aspect).json_binary())
.index(
Index::create()
.unique()
.nulls_not_distinct()
.name("idx-glyph-aspect-image")
.table(Glyph::Table)
.col(Glyph::Aspect)
.col(Glyph::Image)
)
.to_string(PostgresQueryBuilder),
[
r#"CREATE TABLE "glyph" ("#,
r#""image" json,"#,
r#""aspect" jsonb,"#,
r#"CONSTRAINT "idx-glyph-aspect-image" UNIQUE NULLS NOT DISTINCT ("aspect", "image")"#,
r#")"#,
]
.join(" ")
);
Hence, we need to modify this part as well:
sea-query/src/backend/postgres/index.rs
Lines 73 to 80 in c6becfa
fn prepare_index_prefix(&self, create: &IndexCreateStatement, sql: &mut dyn SqlWriter) { | |
if create.primary { | |
write!(sql, "PRIMARY KEY ").unwrap(); | |
} | |
if create.unique { | |
write!(sql, "UNIQUE ").unwrap(); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!! Thanks! @rstular
@billy1624 Glad to help with the project :) I've resolved the merge conflicts now, so this should (hopefully) be ready to merge. |
See you around on GitHub @rstular :) |
PostgreSQL 15 added support (section
E.2.3.1.2. Indexes
) for theNULLS NOT DISTINCT
clause in index creation, which, as the name suggests, causes nulls to not be treated as distinct values when evaluating theUNIQUE
constraint.However, using this feature on an unsupported Postgres version will cause an SQL error - I'm not sure how/if this is handled in this project.
Also closes #509