git.iko.soy/typeable/postgresql-simple
on master help sign in
Merge pull request #173 from alevy/fix/empty_array_to_field

PostgreSQL wants type information for `ARRAY[]`

commit911efd0b88ac5ef46755a7ae44b5545f58a3cd79 authorLeon P Smith <leon.p.smith+github@gmail.com> dateMon 14 Dec 2015, 12:52 (11 years ago) parente14d93045e2ce6
1 file changed+9−6
src/Database/PostgreSQL/Simple/ToField.hs+9−6
src/Database/PostgreSQL/Simple/ToField.hs+9−6
@@ -272,12 +272,15 @@ instance ToField NominalDiffTime where
272272 {-# INLINE toField #-}
273273
274274instance (ToField a) => ToField (PGArray a) where
275− toField xs = Many $
276− Plain (byteString "ARRAY[") :
277− (intersperse (Plain (char8 ',')) . map toField $ fromPGArray xs) ++
278− [Plain (char8 ']')]
279− -- Because the ARRAY[...] input syntax is being used, it is possible
280− -- that the use of type-specific separator characters is unnecessary.
275+ toField pgArray =
276+ case fromPGArray pgArray of
277+ [] -> Plain (byteString "'{}'")
278+ xs -> Many $
279+ Plain (byteString "ARRAY[") :
280+ (intersperse (Plain (char8 ',')) . map toField $ xs) ++
281+ [Plain (char8 ']')]
282+ -- Because the ARRAY[...] input syntax is being used, it is possible
283+ -- that the use of type-specific separator characters is unnecessary.
281284
282285instance (ToField a) => ToField (Vector a) where
283286 toField = toField . PGArray . V.toList