File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
crates/duckdb/src/appender Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -304,4 +304,36 @@ mod test {
304
304
}
305
305
Ok ( ( ) )
306
306
}
307
+
308
+ #[ test]
309
+ fn test_appender_foreign_key_constraint ( ) -> Result < ( ) > {
310
+ let conn = Connection :: open_in_memory ( ) ?;
311
+ conn. execute_batch (
312
+ r"
313
+ CREATE TABLE parent (id INTEGER PRIMARY KEY);
314
+ CREATE TABLE child (
315
+ id INTEGER,
316
+ parent_id INTEGER,
317
+ FOREIGN KEY (parent_id) REFERENCES parent(id)
318
+ );" ,
319
+ ) ?;
320
+ conn. execute ( "INSERT INTO parent VALUES (1)" , [ ] ) ?;
321
+
322
+ let mut appender = conn. appender ( "child" ) ?;
323
+ appender. append_row ( params ! [ 1 , 999 ] ) ?; // Invalid parent_id
324
+
325
+ // Foreign key constraint should be checked during flush
326
+ match appender. flush ( ) {
327
+ Err ( Error :: DuckDBFailure ( _, Some ( msg) ) ) => {
328
+ assert_eq ! (
329
+ msg,
330
+ "Violates foreign key constraint because key \" id: 999\" does not exist in the referenced table"
331
+ ) ;
332
+ }
333
+ Err ( e) => panic ! ( "Expected foreign key constraint error, got: {e:?}" ) ,
334
+ Ok ( _) => panic ! ( "Expected foreign key constraint error, but flush succeeded" ) ,
335
+ }
336
+
337
+ Ok ( ( ) )
338
+ }
307
339
}
You can’t perform that action at this time.
0 commit comments