File tree 3 files changed +30
-10
lines changed
3 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -1104,15 +1104,21 @@ pub trait QueryBuilder:
1104
1104
#[ cfg( feature = "with-uuid" ) ]
1105
1105
Value :: Uuid ( Some ( v) ) => write ! ( s, "'{v}'" ) . unwrap ( ) ,
1106
1106
#[ cfg( feature = "postgres-array" ) ]
1107
- Value :: Array ( _, Some ( v) ) => write ! (
1108
- s,
1109
- "ARRAY [{}]" ,
1110
- v. iter( )
1111
- . map( |element| self . value_to_string( element) )
1112
- . collect:: <Vec <String >>( )
1113
- . join( "," )
1114
- )
1115
- . unwrap ( ) ,
1107
+ Value :: Array ( _, Some ( v) ) => {
1108
+ if v. is_empty ( ) {
1109
+ write ! ( s, "'{{}}'" ) . unwrap ( )
1110
+ } else {
1111
+ write ! (
1112
+ s,
1113
+ "ARRAY [{}]" ,
1114
+ v. iter( )
1115
+ . map( |element| self . value_to_string( element) )
1116
+ . collect:: <Vec <String >>( )
1117
+ . join( "," )
1118
+ )
1119
+ . unwrap ( )
1120
+ }
1121
+ }
1116
1122
#[ cfg( feature = "postgres-vector" ) ]
1117
1123
Value :: Vector ( Some ( v) ) => {
1118
1124
write ! ( s, "'[" ) . unwrap ( ) ;
Original file line number Diff line number Diff line change @@ -849,7 +849,7 @@ pub mod with_array {
849
849
use super :: * ;
850
850
use crate :: RcOrArc ;
851
851
852
- // We only imlement conversion from Vec<T> to Array when T is not u8.
852
+ // We only implement conversion from Vec<T> to Array when T is not u8.
853
853
// This is because for u8's case, there is already conversion to Byte defined above.
854
854
// TODO When negative trait becomes a stable feature, following code can be much shorter.
855
855
pub trait NotU8 { }
Original file line number Diff line number Diff line change @@ -1275,6 +1275,20 @@ fn insert_10() {
1275
1275
) ;
1276
1276
}
1277
1277
1278
+ // regression tests for https://github.com/SeaQL/sea-query/issues/853
1279
+ #[ test]
1280
+ #[ cfg( feature = "postgres-array" ) ]
1281
+ fn insert_issue_853 ( ) {
1282
+ assert_eq ! (
1283
+ Query :: insert( )
1284
+ . into_table( Glyph :: Table )
1285
+ . columns( [ Glyph :: Aspect , Glyph :: Tokens ] )
1286
+ . values_panic( [ 3.1415 . into( ) , Vec :: <String >:: new( ) . into( ) ] )
1287
+ . to_string( PostgresQueryBuilder ) ,
1288
+ r#"INSERT INTO "glyph" ("aspect", "tokens") VALUES (3.1415, '{}')"#
1289
+ ) ;
1290
+ }
1291
+
1278
1292
#[ test]
1279
1293
#[ allow( clippy:: approx_constant) ]
1280
1294
fn insert_on_conflict_1 ( ) {
You can’t perform that action at this time.
0 commit comments