@@ -58,6 +58,8 @@ module Squeal.PostgreSQL.Expression
5858 , nullIf
5959 -- ** Collections
6060 , array
61+ , array1
62+ , array2
6163 , cardinality
6264 , index
6365 , row
@@ -576,8 +578,58 @@ array
576578 :: [Expression outer grp commons schemas params from ty]
577579 -- ^ array elements
578580 -> Expression outer grp commons schemas params from (null ('PGvararray ty))
579−array xs = UnsafeExpression $
580− "ARRAY[" <> commaSeparated (renderSQL <$> xs) <> "]"
581+array xs = UnsafeExpression $ "ARRAY" <>
582+ bracketed (commaSeparated (renderSQL <$> xs))
583+
584+{- | construct a 1-dimensional fixed length array
585+
586+>>> printSQL $ array1 (null_ :* false *: true)
587+ARRAY[NULL, FALSE, TRUE]
588+
589+>>> :type array1 (null_ :* false *: true)
590+array1 (null_ :* false *: true)
591+ :: Expression
592+ outer
593+ grp
594+ commons
595+ schemas
596+ params
597+ from
598+ (null ('PGfixarray '[3] ('Null 'PGbool)))
599+-}
600+array1
601+ :: (n ~ Length tys, SOP.All ((~) ty) tys)
602+ => NP (Expression outer grp commons schemas params from) tys
603+ -> Expression outer grp commons schemas params from (null ('PGfixarray '[n] ty))
604+array1 xs = UnsafeExpression $ "ARRAY" <>
605+ bracketed (renderCommaSeparated renderSQL xs)
606+
607+{- | construct a 1-dimensional fixed length array
608+
609+>>> printSQL $ array2 ((null_ :* false *: true) *: (false :* null_ *: true))
610+ARRAY[[NULL, FALSE, TRUE], [FALSE, NULL, TRUE]]
611+
612+>>> :type array2 ((null_ :* false *: true) *: (false :* null_ *: true))
613+array2 ((null_ :* false *: true) *: (false :* null_ *: true))
614+ :: Expression
615+ outer
616+ grp
617+ commons
618+ schemas
619+ params
620+ from
621+ (null ('PGfixarray '[2, 3] ('Null 'PGbool)))
622+-}
623+array2
624+ :: ( SOP.All ((~) tys) tyss
625+ , SOP.All SOP.SListI tyss
626+ , Length tyss ~ n1
627+ , SOP.All ((~) ty) tys
628+ , Length tys ~ n2 )
629+ => NP (NP (Expression outer grp commons schemas params from)) tyss
630+ -> Expression outer grp commons schemas params from (null ('PGfixarray '[n1,n2] ty))
631+array2 xss = UnsafeExpression $ "ARRAY" <>
632+ bracketed (renderCommaSeparatedConstraint @SOP.SListI (bracketed . renderCommaSeparated renderSQL) xss)
581633
582634-- | >>> printSQL $ cardinality (array [null_, false, true])
583635-- cardinality(ARRAY[NULL, FALSE, TRUE])