@@ -45,6 +45,7 @@ module Squeal.PostgreSQL.Expression
4545 , nullIf
4646 -- ** Collections
4747 , array
48+ , index
4849 , row
4950 , field
5051 -- ** Functions
@@ -195,6 +196,7 @@ import Data.Semigroup hiding (All)
195196import qualified Data.Aeson as JSON
196197import Data.Ratio
197198import Data.String
199+import Data.Word
198200import Generics.SOP hiding (from)
199201import GHC.OverloadedLabels
200202import GHC.TypeLits
@@ -444,6 +446,13 @@ array
444446array xs = UnsafeExpression $
445447 "ARRAY[" <> commaSeparated (renderExpression <$> xs) <> "]"
446448
449+index
450+ :: Word64
451+ -> Expression schema from grouping params (nullity ('PGvararray ty))
452+ -> Expression schema from grouping params (NullifyType ty)
453+index n expr = UnsafeExpression $
454+ parenthesized (renderExpression expr) <> "[" <> fromString (show n) <> "]"
455+
447456instance (KnownSymbol label, label `In` labels) => IsPGlabel label
448457 (Expression schema from grouping params (nullity ('PGenum labels))) where
449458 label = UnsafeExpression $ renderLabel (PGlabel @label)