@@ -82,7 +82,7 @@ let
8282 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
8383 , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])] '[] '[]
8484 manipulation =
85− insertRow_ #tab (Set 2 `as` #col1 :* Default `as` #col2)
85+ insertInto_ #tab (Values_ (2 `as` #col1 :* defaultAs #col2))
8686in printSQL manipulation
8787:}
8888INSERT INTO "tab" ("col1", "col2") VALUES (2, DEFAULT)
@@ -97,8 +97,7 @@ let
9797 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
9898 '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
9999 manipulation =
100− insertRow_ #tab
101− (Set (param @1) `as` #col1 :* Set (param @2) `as` #col2)
100+ insertInto_ #tab (Values_ (param @1 `as` #col1 :* param @2 `as` #col2))
102101in printSQL manipulation
103102:}
104103INSERT INTO "tab" ("col1", "col2") VALUES (($1 :: int4), ($2 :: int4))
@@ -113,7 +112,7 @@ let
113112 , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])] '[]
114113 '["fromOnly" ::: 'NotNull 'PGint4]
115114 manipulation =
116− insertRow #tab (Set 2 `as` #col1 :* Default `as` #col2)
115+ insertInto #tab (Values_ (2 `as` #col1 :* defaultAs #col2))
117116 OnConflictDoRaise (Returning (#col1 `as` #fromOnly))
118117in printSQL manipulation
119118:}
@@ -124,22 +123,18 @@ upsert:
124123>>> :{
125124let
126125 manipulation :: Manipulation
127− '[ "tab" ::: 'Table ('[] :=>
126+ '[ "tab" ::: 'Table ('["uq" ::: 'Unique '["col1"]] :=>
128127 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
129128 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
130129 '[] '[ "sum" ::: 'NotNull 'PGint4]
131130 manipulation =
132− insertRows #tab
133− (Set 2 `as` #col1 :* Set 4 `as` #col2)
134− [Set 6 `as` #col1 :* Set 8 `as` #col2]
135− (OnConflictDoUpdate
136− (UniqueIndexOn #col1)
137− (Set 2 `as` #col1)
138− [#existing ! #col1 .== #excluded ! #col2])
139− (Returning $ (#col1 + #col2) `as` #sum)
131+ insertInto #tab
132+ (Values (2 `as` #col1 :* 4 `as` #col2) [6 `as` #col1 :* 8 `as` #col2])
133+ (OnConflict (OnConstraint #uq) (DoUpdate (2 `as` #col1) [#col1 .== #col2]))
134+ (Returning ((#col1 + #col2) `as` #sum))
140135in printSQL manipulation
141136:}
142−INSERT INTO "tab" AS existing ("col1", "col2") VALUES (2, 4), (6, 8) ON CONFLICT ("col1") DO UPDATE SET "col1" = 2 WHERE ("existing"."col1" = "excluded"."col2") RETURNING ("col1" + "col2") AS "sum"
137+INSERT INTO "tab" ("col1", "col2") VALUES (2, 4), (6, 8) ON CONFLICT ON CONSTRAINT "uq" DO UPDATE SET "col1" = 2 WHERE ("col1" = "col2") RETURNING ("col1" + "col2") AS "sum"
143138
144139query insert:
145140
@@ -156,8 +151,8 @@ let
156151 ])
157152 ] '[] '[]
158153 manipulation =
159− insertQuery_ #tab
160− (selectStar (from (table (#other_tab `as` #t))))
154+ insertInto_ #tab
155+ (Subquery (selectStar (from (table (#other_tab `as` #t)))))
161156in printSQL manipulation
162157:}
163158INSERT INTO "tab" SELECT * FROM "other_tab" AS "t"
@@ -170,9 +165,7 @@ let
170165 '[ "tab" ::: 'Table ('[] :=>
171166 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
172167 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])] '[] '[]
173− manipulation =
174− update_ #tab (Set 2 `as` #col1)
175− (#col1 ./= #col2)
168+ manipulation = update_ #tab (2 `as` #col1) (#col1 ./= #col2)
176169in printSQL manipulation
177170:}
178171UPDATE "tab" SET "col1" = 2 WHERE ("col1" <> "col2")
@@ -230,11 +223,11 @@ let
230223 , "products_deleted" ::: 'Table ProductsTable
231224 ] '[ 'NotNull 'PGdate] '[]
232225 manipulation = with
233− (deleteFrom #products NoUsing (#date .< param @1) ReturningStar `as` #deleted_rows)
234− (insertQuery_ #products_deleted (selectStar (from (view (#deleted_rows `as` #t)))))
226+ (deleteFrom #products NoUsing (#date .< param @1) ReturningStar `as` #del)
227+ (insertInto_ #products_deleted (Subquery (selectStar (from (view #del)))))
235228in printSQL manipulation
236229:}
237−WITH "deleted_rows" AS (DELETE FROM "products" WHERE ("date" < ($1 :: date)) RETURNING *) INSERT INTO "products_deleted" SELECT * FROM "deleted_rows" AS "t"
230+WITH "del" AS (DELETE FROM "products" WHERE ("date" < ($1 :: date)) RETURNING *) INSERT INTO "products_deleted" SELECT * FROM "del" AS "del"
238231-}
239232
240233newtype Manipulation