File tree Expand file tree Collapse file tree 4 files changed +32
-0
lines changed Expand file tree Collapse file tree 4 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -197,6 +197,8 @@ pub enum ErrorKind {
197
197
NotNullViolation ,
198
198
/// Check constraint violation.
199
199
CheckViolation ,
200
+ /// Exclusion constraint violation.
201
+ ExclusionViolation ,
200
202
/// An unmapped error.
201
203
Other ,
202
204
}
Original file line number Diff line number Diff line change @@ -214,6 +214,7 @@ impl DatabaseError for PgDatabaseError {
214
214
error_codes:: FOREIGN_KEY_VIOLATION => ErrorKind :: ForeignKeyViolation ,
215
215
error_codes:: NOT_NULL_VIOLATION => ErrorKind :: NotNullViolation ,
216
216
error_codes:: CHECK_VIOLATION => ErrorKind :: CheckViolation ,
217
+ error_codes:: EXCLUSION_VIOLATION => ErrorKind :: ExclusionViolation ,
217
218
_ => ErrorKind :: Other ,
218
219
}
219
220
}
@@ -239,4 +240,6 @@ pub(crate) mod error_codes {
239
240
pub const NOT_NULL_VIOLATION : & str = "23502" ;
240
241
/// Caused when a check constraint is violated.
241
242
pub const CHECK_VIOLATION : & str = "23514" ;
243
+ /// Caused when a exclude constraint is violated.
244
+ pub const EXCLUSION_VIOLATION : & str = "23P01" ;
242
245
}
Original file line number Diff line number Diff line change @@ -75,6 +75,28 @@ async fn it_fails_with_check_violation() -> anyhow::Result<()> {
75
75
Ok ( ( ) )
76
76
}
77
77
78
+ #[ sqlx_macros:: test]
79
+ async fn it_fails_with_exclude_violation ( ) -> anyhow:: Result < ( ) > {
80
+ let mut conn = new :: < Postgres > ( ) . await ?;
81
+ let mut tx = conn. begin ( ) . await ?;
82
+
83
+ sqlx:: query ( "INSERT INTO circles VALUES (circle('(0,0)'::point, 5.0));" )
84
+ . execute ( & mut * tx)
85
+ . await ?;
86
+
87
+ let res: Result < _ , sqlx:: Error > =
88
+ sqlx:: query ( "INSERT INTO circles VALUES (circle('(0,2.0)'::point, 2.0));" )
89
+ . execute ( & mut * tx)
90
+ . await ;
91
+ let err = res. unwrap_err ( ) ;
92
+
93
+ let err = err. into_database_error ( ) . unwrap ( ) ;
94
+
95
+ assert_eq ! ( err. kind( ) , ErrorKind :: ExclusionViolation ) ;
96
+
97
+ Ok ( ( ) )
98
+ }
99
+
78
100
#[ sqlx_macros:: test]
79
101
async fn it_fails_with_begin_failed ( ) -> anyhow:: Result < ( ) > {
80
102
let mut conn = new :: < Postgres > ( ) . await ?;
Original file line number Diff line number Diff line change @@ -63,3 +63,8 @@ CREATE SCHEMA IF NOT EXISTS foo;
63
63
CREATE TYPE foo ." Foo" as ENUM (' Bar' , ' Baz' );
64
64
65
65
CREATE TABLE mytable (f HSTORE);
66
+
67
+ CREATE TABLE circles (
68
+ c circle ,
69
+ EXCLUDE USING gist (c WITH &&)
70
+ );
You can’t perform that action at this time.
0 commit comments