@@ -140,12 +140,12 @@ instance PGNum ty
140140 . fromString
141141 . show
142142
143−instance PGFractional ty => Fractional
143+instance PGFloating ty => Fractional
144144 (Expression params tables grouping ('Required (nullity ty))) where
145145 (/) = unsafeBinaryOp "/"
146146 fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
147147
148−instance (PGFloating ty, PGCast 'PGNumeric ty, PGTyped ty) => Floating
148+instance (PGFloating ty, PGTyped ty) => Floating
149149 (Expression params tables grouping ('Required (nullity ty))) where
150150 pi = UnsafeExpression "pi()"
151151 exp = unsafeFunction "exp"
@@ -158,12 +158,12 @@ instance (PGFloating ty, PGCast 'PGNumeric ty, PGTyped ty) => Floating
158158 logBaseNumeric
159159 :: Expression params tables grouping ('Required (nullity ty))
160160 -> Expression params tables grouping ('Required (nullity ty))
161− -> Expression params tables grouping ('Required (nullity 'PGNumeric))
161+ -> Expression params tables grouping ('Required (nullity 'PGnumeric))
162162 logBaseNumeric b' y' = UnsafeExpression $ mconcat
163163 [ "log("
164− , renderExpression b' <> "::numeric"
164+ , renderExpression (cast numeric b')
165165 , ", "
166− , renderExpression y' <> "::numeric"
166+ , renderExpression (cast numeric y')
167167 , ")"
168168 ]
169169 sin = unsafeFunction "sin"
@@ -187,75 +187,62 @@ atan2
187187atan2 y x = UnsafeExpression $
188188 "atan2(" <> renderExpression y <> ", " <> renderExpression x <> ")"
189189
190−class PGCast (ty0 :: PGType) (ty1 :: PGType) where
191− cast
192− :: TypeExpression ('Required ('Null ty1))
193− -> Expression params tables grouping ('Required (nullity ty0))
194− -> Expression params tables grouping ('Required (nullity ty1))
195− cast ty x = UnsafeExpression $
196− "(" <> renderExpression x <> "::" <> renderTypeExpression ty <> ")"
197−instance PGCast 'PGInt2 'PGInt2
198−instance PGCast 'PGInt2 'PGInt4
199−instance PGCast 'PGInt2 'PGInt8
200−instance PGCast 'PGInt4 'PGInt2
201−instance PGCast 'PGInt4 'PGInt4
202−instance PGCast 'PGInt4 'PGInt8
203−instance PGCast 'PGInt8 'PGInt2
204−instance PGCast 'PGInt8 'PGInt4
205−instance PGCast 'PGInt8 'PGInt8
206−instance PGCast 'PGInt8 'PGFloat4
207−instance PGCast 'PGInt8 'PGFloat8
208−instance PGCast 'PGInt8 'PGNumeric
190+cast
191+ :: TypeExpression ('Required ('Null ty1))
192+ -> Expression params tables grouping ('Required (nullity ty0))
193+ -> Expression params tables grouping ('Required (nullity ty1))
194+cast ty x = UnsafeExpression $
195+ "(" <> renderExpression x <> " :: " <> renderTypeExpression ty <> ")"
209196
210197div
211− :: (PGNum ty, PGTyped ty, PGCast 'PGInt8 ty, PGCast ty 'PGInt8)
198+ :: PGIntegral ty
212199 => Expression params tables grouping ('Required (nullity ty))
213200 -> Expression params tables grouping ('Required (nullity ty))
214201 -> Expression params tables grouping ('Required (nullity ty))
215202div = unsafeBinaryOp "/"
216203
217204mod
218− :: (PGNum ty, PGTyped ty, PGCast 'PGInt8 ty, PGCast ty 'PGInt8)
205+ :: PGIntegral ty
219206 => Expression params tables grouping ('Required (nullity ty))
220207 -> Expression params tables grouping ('Required (nullity ty))
221208 -> Expression params tables grouping ('Required (nullity ty))
222209mod = unsafeBinaryOp "%"
223210
224211truncate
225− :: (PGFractional frac, PGCast 'PGInt4 int, PGTyped int)
212+ :: (PGFloating frac, PGTyped int)
226213 => Expression params tables grouping ('Required (nullity frac))
227214 -> Expression params tables grouping ('Required (nullity int))
228215truncate = cast pgtype . truncate'
229216 where
230217 truncate'
231218 :: Expression params tables grouping ('Required (nullity frac))
232− -> Expression params tables grouping ('Required (nullity 'PGInt4))
219+ -> Expression params tables grouping ('Required (nullity frac))
233220 truncate' = unsafeFunction "trunc"
234221
235222round
236− :: (PGFractional frac, PGCast 'PGInt4 int, PGTyped int)
223+ :: (PGFloating frac, PGTyped int)
237224 => Expression params tables grouping ('Required (nullity frac))
238225 -> Expression params tables grouping ('Required (nullity int))
239226round = cast pgtype . round'
240227 where
241228 round'
242229 :: Expression params tables grouping ('Required (nullity frac))
243− -> Expression params tables grouping ('Required (nullity 'PGInt4))
230+ -> Expression params tables grouping ('Required (nullity frac))
244231 round' = unsafeFunction "round"
245232
246233ceiling
247− :: (PGFractional frac, PGCast 'PGInt4 int, PGTyped int)
234+ :: (PGFloating frac, PGTyped int)
248235 => Expression params tables grouping ('Required (nullity frac))
249236 -> Expression params tables grouping ('Required (nullity int))
250237ceiling = cast pgtype . ceiling'
251238 where
252239 ceiling'
253240 :: Expression params tables grouping ('Required (nullity frac))
254− -> Expression params tables grouping ('Required (nullity 'PGInt4))
241+ -> Expression params tables grouping ('Required (nullity frac))
255242 ceiling' = unsafeFunction "ceiling"
256243
257244instance IsString
258− (Expression params tables grouping ('Required (nullity 'PGText))) where
245+ (Expression params tables grouping ('Required (nullity 'PGtext))) where
259246 fromString str = UnsafeExpression $
260247 "E\'" <> fromString (escape =<< str) <> "\'"
261248 where
@@ -271,7 +258,7 @@ instance IsString
271258 c -> [c]
272259
273260type Condition params tables grouping =
274− Expression params tables grouping ('Required ('NotNull 'PGBool))
261+ Expression params tables grouping ('Required ('NotNull 'PGbool))
275262
276263true :: Condition params tables grouping
277264true = UnsafeExpression "TRUE"
@@ -323,37 +310,37 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
323310(==*)
324311 :: Expression params tables grouping ('Required (nullity ty))
325312 -> Expression params tables grouping ('Required (nullity ty))
326− -> Expression params tables grouping ('Required (nullity 'PGBool))
313+ -> Expression params tables grouping ('Required (nullity 'PGbool))
327314(==*) = unsafeBinaryOp "="
328315
329316(/=*)
330317 :: Expression params tables grouping ('Required (nullity ty))
331318 -> Expression params tables grouping ('Required (nullity ty))
332− -> Expression params tables grouping ('Required (nullity 'PGBool))
319+ -> Expression params tables grouping ('Required (nullity 'PGbool))
333320(/=*) = unsafeBinaryOp "<>"
334321
335322(>=*)
336323 :: Expression params tables grouping ('Required (nullity ty))
337324 -> Expression params tables grouping ('Required (nullity ty))
338− -> Expression params tables grouping ('Required (nullity 'PGBool))
325+ -> Expression params tables grouping ('Required (nullity 'PGbool))
339326(>=*) = unsafeBinaryOp ">="
340327
341328(<*)
342329 :: Expression params tables grouping ('Required (nullity ty))
343330 -> Expression params tables grouping ('Required (nullity ty))
344− -> Expression params tables grouping ('Required (nullity 'PGBool))
331+ -> Expression params tables grouping ('Required (nullity 'PGbool))
345332(<*) = unsafeBinaryOp "<"
346333
347334(<=*)
348335 :: Expression params tables grouping ('Required (nullity ty))
349336 -> Expression params tables grouping ('Required (nullity ty))
350− -> Expression params tables grouping ('Required (nullity 'PGBool))
337+ -> Expression params tables grouping ('Required (nullity 'PGbool))
351338(<=*) = unsafeBinaryOp "<="
352339
353340(>*)
354341 :: Expression params tables grouping ('Required (nullity ty))
355342 -> Expression params tables grouping ('Required (nullity ty))
356− -> Expression params tables grouping ('Required (nullity 'PGBool))
343+ -> Expression params tables grouping ('Required (nullity 'PGbool))
357344(>*) = unsafeBinaryOp ">"
358345
359346data SortExpression params tables grouping where
@@ -640,91 +627,89 @@ newtype TypeExpression (ty :: ColumnType)
640627 = UnsafeTypeExpression { renderTypeExpression :: ByteString }
641628 deriving (Show,Eq)
642629
643−bool :: TypeExpression ('Required ('Null 'PGBool))
630+bool :: TypeExpression ('Required ('Null 'PGbool))
644631bool = UnsafeTypeExpression "bool"
645−int2 :: TypeExpression ('Required ('Null 'PGInt2))
632+int2 :: TypeExpression ('Required ('Null 'PGint2))
646633int2 = UnsafeTypeExpression "int2"
647−smallint :: TypeExpression ('Required ('Null 'PGInt2))
634+smallint :: TypeExpression ('Required ('Null 'PGint2))
648635smallint = UnsafeTypeExpression "smallint"
649−int4 :: TypeExpression ('Required ('Null 'PGInt4))
636+int4 :: TypeExpression ('Required ('Null 'PGint4))
650637int4 = UnsafeTypeExpression "int4"
651−int :: TypeExpression ('Required ('Null 'PGInt4))
638+int :: TypeExpression ('Required ('Null 'PGint4))
652639int = UnsafeTypeExpression "int"
653−integer :: TypeExpression ('Required ('Null 'PGInt4))
640+integer :: TypeExpression ('Required ('Null 'PGint4))
654641integer = UnsafeTypeExpression "integer"
655−int8 :: TypeExpression ('Required ('Null 'PGInt8))
642+int8 :: TypeExpression ('Required ('Null 'PGint8))
656643int8 = UnsafeTypeExpression "int8"
657−bigint :: TypeExpression ('Required ('Null 'PGInt8))
644+bigint :: TypeExpression ('Required ('Null 'PGint8))
658645bigint = UnsafeTypeExpression "bigint"
659−numeric :: TypeExpression ('Required ('Null 'PGNumeric))
646+numeric :: TypeExpression ('Required ('Null 'PGnumeric))
660647numeric = UnsafeTypeExpression "numeric"
661−float4 :: TypeExpression ('Required ('Null 'PGFloat4))
648+float4 :: TypeExpression ('Required ('Null 'PGfloat4))
662649float4 = UnsafeTypeExpression "float4"
663−real :: TypeExpression ('Required ('Null 'PGFloat4))
650+real :: TypeExpression ('Required ('Null 'PGfloat4))
664651real = UnsafeTypeExpression "real"
665−float8 :: TypeExpression ('Required ('Null 'PGFloat8))
652+float8 :: TypeExpression ('Required ('Null 'PGfloat8))
666653float8 = UnsafeTypeExpression "float8"
667−doublePrecision :: TypeExpression ('Required ('Null 'PGFloat8))
654+doublePrecision :: TypeExpression ('Required ('Null 'PGfloat8))
668655doublePrecision = UnsafeTypeExpression "double precision"
669−serial2 :: TypeExpression ('Optional ('NotNull 'PGInt2))
656+serial2 :: TypeExpression ('Optional ('NotNull 'PGint2))
670657serial2 = UnsafeTypeExpression "serial2"
671−smallserial :: TypeExpression ('Optional ('NotNull 'PGInt2))
658+smallserial :: TypeExpression ('Optional ('NotNull 'PGint2))
672659smallserial = UnsafeTypeExpression "smallserial"
673−serial4 :: TypeExpression ('Optional ('NotNull 'PGInt4))
660+serial4 :: TypeExpression ('Optional ('NotNull 'PGint4))
674661serial4 = UnsafeTypeExpression "serial4"
675−serial :: TypeExpression ('Optional ('NotNull 'PGInt4))
662+serial :: TypeExpression ('Optional ('NotNull 'PGint4))
676663serial = UnsafeTypeExpression "serial"
677−serial8 :: TypeExpression ('Optional ('NotNull 'PGInt8))
664+serial8 :: TypeExpression ('Optional ('NotNull 'PGint8))
678665serial8 = UnsafeTypeExpression "serial8"
679−bigserial :: TypeExpression ('Optional ('NotNull 'PGInt8))
666+bigserial :: TypeExpression ('Optional ('NotNull 'PGint8))
680667bigserial = UnsafeTypeExpression "bigserial"
681−money :: TypeExpression ('Required ('Null 'PGMoney))
682−money = UnsafeTypeExpression "money"
683−text :: TypeExpression ('Required ('Null 'PGText))
668+text :: TypeExpression ('Required ('Null 'PGtext))
684669text = UnsafeTypeExpression "text"
685670char
686671 :: KnownNat n
687672 => proxy n
688− -> TypeExpression ('Required ('Null ('PGChar n)))
673+ -> TypeExpression ('Required ('Null ('PGchar n)))
689674char (_ :: proxy n) = UnsafeTypeExpression $
690675 "char(" <> fromString (show (natVal' (proxy# :: Proxy# n))) <> ")"
691676character
692677 :: KnownNat n
693678 => proxy n
694− -> TypeExpression ('Required ('Null ('PGChar n)))
679+ -> TypeExpression ('Required ('Null ('PGchar n)))
695680character (_ :: proxy n) = UnsafeTypeExpression $
696681 "character(" <> fromString (show (natVal' (proxy# :: Proxy# n))) <> ")"
697682varchar
698683 :: KnownNat n
699684 => proxy n
700− -> TypeExpression ('Required ('Null ('PGVarChar n)))
685+ -> TypeExpression ('Required ('Null ('PGvarchar n)))
701686varchar (_ :: proxy n) = UnsafeTypeExpression $
702687 "varchar(" <> fromString (show (natVal' (proxy# :: Proxy# n))) <> ")"
703688characterVarying
704689 :: KnownNat n
705690 => proxy n
706− -> TypeExpression ('Required ('Null ('PGVarChar n)))
707−characterVarying (_ :: proxy n) = UnsafeTypeExpression $
708− "character varying(" <> fromString (show (natVal' (proxy# :: Proxy# n))) <> ")"
709−bytea :: TypeExpression ('Required ('Null ('PGBytea)))
691+ -> TypeExpression ('Required ('Null ('PGvarchar n)))
692+characterVarying p = UnsafeTypeExpression $
693+ "character varying(" <> renderNat p <> ")"
694+bytea :: TypeExpression ('Required ('Null ('PGbytea)))
710695bytea = UnsafeTypeExpression "bytea"
711−timestamp :: TypeExpression ('Required ('Null ('PGTimestamp)))
696+timestamp :: TypeExpression ('Required ('Null ('PGtimestamp)))
712697timestamp = UnsafeTypeExpression "timestamp"
713−timestampWithTimeZone :: TypeExpression ('Required ('Null ('PGTimestampTZ)))
698+timestampWithTimeZone :: TypeExpression ('Required ('Null ('PGtimestamptz)))
714699timestampWithTimeZone = UnsafeTypeExpression "timestamp with time zone"
715−date :: TypeExpression ('Required ('Null ('PGDate)))
700+date :: TypeExpression ('Required ('Null ('PGdate)))
716701date = UnsafeTypeExpression "date"
717−time :: TypeExpression ('Required ('Null ('PGTime)))
702+time :: TypeExpression ('Required ('Null ('PGtime)))
718703time = UnsafeTypeExpression "time"
719−timeWithTimeZone :: TypeExpression ('Required ('Null ('PGTimeTZ)))
704+timeWithTimeZone :: TypeExpression ('Required ('Null ('PGtimetz)))
720705timeWithTimeZone = UnsafeTypeExpression "time with time zone"
721−interval :: TypeExpression ('Required ('Null ('PGInterval)))
706+interval :: TypeExpression ('Required ('Null ('PGinterval)))
722707interval = UnsafeTypeExpression "interval"
723−uuid :: TypeExpression ('Required ('Null ('PGUuid)))
708+uuid :: TypeExpression ('Required ('Null ('PGuuid)))
724709uuid = UnsafeTypeExpression "uuid"
725−json :: TypeExpression ('Required ('Null ('PGJson)))
710+json :: TypeExpression ('Required ('Null ('PGjson)))
726711json = UnsafeTypeExpression "json"
727−jsonb :: TypeExpression ('Required ('Null ('PGJsonb)))
712+jsonb :: TypeExpression ('Required ('Null ('PGjsonb)))
728713jsonb = UnsafeTypeExpression "jsonb"
729714
730715notNull
@@ -740,27 +725,26 @@ default_ x ty = UnsafeTypeExpression $
740725
741726class PGTyped (ty :: PGType) where
742727 pgtype :: TypeExpression ('Required ('Null ty))
743−instance PGTyped 'PGBool where pgtype = bool
744−instance PGTyped 'PGInt2 where pgtype = int2
745−instance PGTyped 'PGInt4 where pgtype = int4
746−instance PGTyped 'PGInt8 where pgtype = int8
747−instance PGTyped 'PGNumeric where pgtype = numeric
748−instance PGTyped 'PGFloat4 where pgtype = float4
749−instance PGTyped 'PGFloat8 where pgtype = float8
750−instance PGTyped 'PGMoney where pgtype = money
751−instance PGTyped 'PGText where pgtype = text
752−instance KnownNat n => PGTyped ('PGChar n) where pgtype = char (Proxy @n)
753−instance KnownNat n => PGTyped ('PGVarChar n) where pgtype = varchar (Proxy @n)
754−instance PGTyped 'PGBytea where pgtype = bytea
755−instance PGTyped 'PGTimestamp where pgtype = timestamp
756−instance PGTyped 'PGTimestampTZ where pgtype = timestampWithTimeZone
757−instance PGTyped 'PGDate where pgtype = date
758−instance PGTyped 'PGTime where pgtype = time
759−instance PGTyped 'PGTimeTZ where pgtype = timeWithTimeZone
760−instance PGTyped 'PGInterval where pgtype = interval
761−instance PGTyped 'PGUuid where pgtype = uuid
762−instance PGTyped 'PGJson where pgtype = json
763−instance PGTyped 'PGJsonb where pgtype = jsonb
728+instance PGTyped 'PGbool where pgtype = bool
729+instance PGTyped 'PGint2 where pgtype = int2
730+instance PGTyped 'PGint4 where pgtype = int4
731+instance PGTyped 'PGint8 where pgtype = int8
732+instance PGTyped 'PGnumeric where pgtype = numeric
733+instance PGTyped 'PGfloat4 where pgtype = float4
734+instance PGTyped 'PGfloat8 where pgtype = float8
735+instance PGTyped 'PGtext where pgtype = text
736+instance KnownNat n => PGTyped ('PGchar n) where pgtype = char (Proxy @n)
737+instance KnownNat n => PGTyped ('PGvarchar n) where pgtype = varchar (Proxy @n)
738+instance PGTyped 'PGbytea where pgtype = bytea
739+instance PGTyped 'PGtimestamp where pgtype = timestamp
740+instance PGTyped 'PGtimestamptz where pgtype = timestampWithTimeZone
741+instance PGTyped 'PGdate where pgtype = date
742+instance PGTyped 'PGtime where pgtype = time
743+instance PGTyped 'PGtimetz where pgtype = timeWithTimeZone
744+instance PGTyped 'PGinterval where pgtype = interval
745+instance PGTyped 'PGuuid where pgtype = uuid
746+instance PGTyped 'PGjson where pgtype = json
747+instance PGTyped 'PGjsonb where pgtype = jsonb
764748
765749{-----------------------------------------
766750statements
@@ -1043,8 +1027,7 @@ dropNotNull
10431027dropNotNull = UnsafeAlterColumn $ "DROP NOT NULL"
10441028
10451029alterType
1046− :: PGCast ty0 ty1
1047− => TypeExpression (optionality (nullity ty1))
1030+ :: TypeExpression (optionality (nullity ty1))
10481031 -> AlterColumn (optionality (nullity ty0)) (optionality (nullity ty1))
10491032alterType ty = UnsafeAlterColumn $ "TYPE " <> renderTypeExpression ty
10501033
@@ -1210,3 +1193,6 @@ renderCommaSeparatedMaybe render
12101193
12111194renderSymbol :: KnownSymbol str => Proxy# str -> ByteString
12121195renderSymbol p = fromString $ symbolVal' p
1196+
1197+renderNat :: KnownNat n => proxy n -> ByteString
1198+renderNat (_ :: proxy n) = fromString (show (natVal' (proxy# :: Proxy# n)))