on dev help sign in
fix parenthesization of indexes
commit121553e511cec8e4e3eb037714800a2a6bb41ccb authorEitan Chatav <eitan@EEM109LMBP-1.local> dateMon 2 Sep 2019, 09:33 (7 years ago) parentf57b03b
1 file changed+15−3
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+15−3
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+15−3
@@ -1075,11 +1075,11 @@ let
10751075 setup :: Definition (Public '[]) (Public '["tab" ::: 'Table Table, "ix" ::: 'Index])
10761076 setup =
10771077 createTable #tab (nullable int `as` #a :* nullable real `as` #b) Nil >>>
1078− createIndex #ix #tab Gin [#a & AscNullsFirst, #b & AscNullsLast]
1078+ createIndex #ix #tab Btree [#a & AscNullsFirst, #b & AscNullsLast]
10791079in printSQL setup
10801080:}
10811081CREATE TABLE "tab" ("a" int NULL, "b" real NULL);
1082−CREATE INDEX "ix" ON "tab" USING gin (("a" ASC NULLS FIRST), ("b" ASC NULLS LAST));
1082+CREATE INDEX "ix" ON "tab" USING btree (("a") ASC NULLS FIRST, ("b") ASC NULLS LAST);
10831083-}
10841084createIndex
10851085 :: (Has sch schemas schema, Has tab schema ('Table table), KnownSymbol ix)
@@ -1091,8 +1091,20 @@ createIndex
10911091createIndex ix tab method cols = UnsafeDefinition $
10921092 "CREATE" <+> "INDEX" <+> renderSQL ix <+> "ON" <+> renderSQL tab
10931093 <+> "USING" <+> renderSQL method
1094− <+> parenthesized (commaSeparated (parenthesized . renderSQL <$> cols))
1094+ <+> parenthesized (commaSeparated (renderIndex <$> cols))
10951095 <> ";"
1096+ where
1097+ renderIndex = \case
1098+ Asc expression -> parenthesized (renderSQL expression) <+> "ASC"
1099+ Desc expression -> parenthesized (renderSQL expression) <+> "DESC"
1100+ AscNullsFirst expression -> parenthesized (renderSQL expression)
1101+ <+> "ASC NULLS FIRST"
1102+ DescNullsFirst expression -> parenthesized (renderSQL expression)
1103+ <+> "DESC NULLS FIRST"
1104+ AscNullsLast expression -> parenthesized (renderSQL expression)
1105+ <+> "ASC NULLS LAST"
1106+ DescNullsLast expression -> parenthesized (renderSQL expression)
1107+ <+> "DESC NULLS LAST"
10961108
10971109data IndexMethod
10981110 = Btree