@@ -82,7 +82,7 @@ let
82 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
82 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
83 , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])] '[] '[]
83 , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])] '[] '[]
84 manipulation =
84 manipulation =
85− insertRow_ #tab (Set 2 `as` #col1 :* Default `as` #col2)
85+ insertInto_ #tab (Values_ (2 `as` #col1 :* defaultAs #col2))
86in printSQL manipulation
86in printSQL manipulation
88INSERT INTO "tab" ("col1", "col2") VALUES (2, DEFAULT)
88INSERT INTO "tab" ("col1", "col2") VALUES (2, DEFAULT)
@@ -97,8 +97,7 @@ let
97 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
97 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
98 '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
98 '[ 'NotNull 'PGint4, 'NotNull 'PGint4 ] '[]
99 manipulation =
99 manipulation =
101− (Set (param @1) `as` #col1 :* Set (param @2) `as` #col2)
100+ insertInto_ #tab (Values_ (param @1 `as` #col1 :* param @2 `as` #col2))
102in printSQL manipulation
101in printSQL manipulation
104INSERT INTO "tab" ("col1", "col2") VALUES (($1 :: int4), ($2 :: int4))
103INSERT INTO "tab" ("col1", "col2") VALUES (($1 :: int4), ($2 :: int4))
@@ -113,7 +112,7 @@ let
113 , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])] '[]
112 , "col2" ::: 'Def :=> 'NotNull 'PGint4 ])] '[]
114 '["fromOnly" ::: 'NotNull 'PGint4]
113 '["fromOnly" ::: 'NotNull 'PGint4]
115 manipulation =
114 manipulation =
116− insertRow #tab (Set 2 `as` #col1 :* Default `as` #col2)
115+ insertInto #tab (Values_ (2 `as` #col1 :* defaultAs #col2))
117 OnConflictDoRaise (Returning (#col1 `as` #fromOnly))
116 OnConflictDoRaise (Returning (#col1 `as` #fromOnly))
118in printSQL manipulation
117in printSQL manipulation
@@ -124,22 +123,18 @@ upsert:
126 manipulation :: Manipulation
125 manipulation :: Manipulation
127− '[ "tab" ::: 'Table ('[] :=>
126+ '[ "tab" ::: 'Table ('["uq" ::: 'Unique '["col1"]] :=>
128 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
127 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
129 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
128 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])]
130 '[] '[ "sum" ::: 'NotNull 'PGint4]
129 '[] '[ "sum" ::: 'NotNull 'PGint4]
131 manipulation =
130 manipulation =
132− insertRows #tab
131+ insertInto #tab
133− (Set 2 `as` #col1 :* Set 4 `as` #col2)
132+ (Values (2 `as` #col1 :* 4 `as` #col2) [6 `as` #col1 :* 8 `as` #col2])
134− [Set 6 `as` #col1 :* Set 8 `as` #col2]
133+ (OnConflict (OnConstraint #uq) (DoUpdate (2 `as` #col1) [#col1 .== #col2]))
136− (UniqueIndexOn #col1)
138− [#existing ! #col1 .== #excluded ! #col2])
139− (Returning $ (#col1 + #col2) `as` #sum)
134+ (Returning ((#col1 + #col2) `as` #sum))
140in printSQL manipulation
135in printSQL manipulation
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"
144query insert:
139query insert:
@@ -156,8 +151,8 @@ let
157 ] '[] '[]
152 ] '[] '[]
158 manipulation =
153 manipulation =
159− insertQuery_ #tab
154+ insertInto_ #tab
160− (selectStar (from (table (#other_tab `as` #t))))
155+ (Subquery (selectStar (from (table (#other_tab `as` #t)))))
161in printSQL manipulation
156in printSQL manipulation
163INSERT INTO "tab" SELECT * FROM "other_tab" AS "t"
158INSERT INTO "tab" SELECT * FROM "other_tab" AS "t"
@@ -170,9 +165,7 @@ let
170 '[ "tab" ::: 'Table ('[] :=>
165 '[ "tab" ::: 'Table ('[] :=>
171 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
166 '[ "col1" ::: 'NoDef :=> 'NotNull 'PGint4
172 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])] '[] '[]
167 , "col2" ::: 'NoDef :=> 'NotNull 'PGint4 ])] '[] '[]
174− update_ #tab (Set 2 `as` #col1)
168+ manipulation = update_ #tab (2 `as` #col1) (#col1 ./= #col2)
176in printSQL manipulation
169in printSQL manipulation
178UPDATE "tab" SET "col1" = 2 WHERE ("col1" <> "col2")
171UPDATE "tab" SET "col1" = 2 WHERE ("col1" <> "col2")
@@ -230,11 +223,11 @@ let
230 , "products_deleted" ::: 'Table ProductsTable
223 , "products_deleted" ::: 'Table ProductsTable
231 ] '[ 'NotNull 'PGdate] '[]
224 ] '[ 'NotNull 'PGdate] '[]
232 manipulation = with
225 manipulation = with
233− (deleteFrom #products NoUsing (#date .< param @1) ReturningStar `as` #deleted_rows)
226+ (deleteFrom #products NoUsing (#date .< param @1) ReturningStar `as` #del)
234− (insertQuery_ #products_deleted (selectStar (from (view (#deleted_rows `as` #t)))))
227+ (insertInto_ #products_deleted (Subquery (selectStar (from (view #del)))))
235in printSQL manipulation
228in printSQL manipulation
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"
240newtype Manipulation
233newtype Manipulation