File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -197,6 +197,8 @@ pub enum ErrorKind {
197197 NotNullViolation ,
198198 /// Check constraint violation.
199199 CheckViolation ,
200+ /// Exclusion constraint violation.
201+ ExclusionViolation ,
200202 /// An unmapped error.
201203 Other ,
202204}
Original file line number Diff line number Diff line change @@ -214,6 +214,7 @@ impl DatabaseError for PgDatabaseError {
214214 error_codes:: FOREIGN_KEY_VIOLATION => ErrorKind :: ForeignKeyViolation ,
215215 error_codes:: NOT_NULL_VIOLATION => ErrorKind :: NotNullViolation ,
216216 error_codes:: CHECK_VIOLATION => ErrorKind :: CheckViolation ,
217+ error_codes:: EXCLUSION_VIOLATION => ErrorKind :: ExclusionViolation ,
217218 _ => ErrorKind :: Other ,
218219 }
219220 }
@@ -239,4 +240,6 @@ pub(crate) mod error_codes {
239240 pub const NOT_NULL_VIOLATION : & str = "23502" ;
240241 /// Caused when a check constraint is violated.
241242 pub const CHECK_VIOLATION : & str = "23514" ;
243+ /// Caused when a exclude constraint is violated.
244+ pub const EXCLUSION_VIOLATION : & str = "23P01" ;
242245}
Original file line number Diff line number Diff line change @@ -75,6 +75,28 @@ async fn it_fails_with_check_violation() -> anyhow::Result<()> {
7575 Ok ( ( ) )
7676}
7777
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+
78100#[ sqlx_macros:: test]
79101async fn it_fails_with_begin_failed ( ) -> anyhow:: Result < ( ) > {
80102 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;
6363CREATE TYPE foo ." Foo" as ENUM (' Bar' , ' Baz' );
6464
6565CREATE 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