@@ -3,7 +3,7 @@ use futures::{Stream, StreamExt, TryStreamExt};
3
3
use sqlx:: postgres:: types:: Oid ;
4
4
use sqlx:: postgres:: {
5
5
PgAdvisoryLock , PgConnectOptions , PgConnection , PgDatabaseError , PgErrorPosition , PgListener ,
6
- PgPoolOptions , PgRow , PgSeverity , Postgres ,
6
+ PgPoolOptions , PgRow , PgSeverity , Postgres , PG_COPY_MAX_DATA_LEN ,
7
7
} ;
8
8
use sqlx:: { Column , Connection , Executor , Row , Statement , TypeInfo } ;
9
9
use sqlx_core:: { bytes:: Bytes , error:: BoxDynError } ;
@@ -2042,3 +2042,23 @@ async fn test_issue_3052() {
2042
2042
"expected encode error, got {too_large_error:?}" ,
2043
2043
) ;
2044
2044
}
2045
+
2046
+ #[ sqlx_macros:: test]
2047
+ async fn test_pg_copy_chunked ( ) -> anyhow:: Result < ( ) > {
2048
+ let mut conn = new :: < Postgres > ( ) . await ?;
2049
+
2050
+ let mut row = "1" . repeat ( PG_COPY_MAX_DATA_LEN / 10 - 1 ) ;
2051
+ row. push_str ( "\n " ) ;
2052
+
2053
+ // creates a payload with COPY_MAX_DATA_LEN + 1 as size
2054
+ let mut payload = row. repeat ( 10 ) ;
2055
+ payload. push_str ( "12345678\n " ) ;
2056
+
2057
+ assert_eq ! ( payload. len( ) , PG_COPY_MAX_DATA_LEN + 1 ) ;
2058
+
2059
+ let mut copy = conn. copy_in_raw ( "COPY products(name) FROM STDIN" ) . await ?;
2060
+
2061
+ assert ! ( copy. send( payload. as_bytes( ) ) . await . is_ok( ) ) ;
2062
+ assert ! ( copy. finish( ) . await . is_ok( ) ) ;
2063
+ Ok ( ( ) )
2064
+ }
0 commit comments