@@ -179,7 +179,9 @@ protected function upsertCount(array $values): int
179
179
[
180
180
'value ' => match ($ driver = $ this ->connection ()->getDriverName ()) {
181
181
'mariadb ' , 'mysql ' => new Expression ('`value` + values(`value`) ' ),
182
- 'pgsql ' , 'sqlite ' => new Expression ('"pulse_aggregates"."value" + "excluded"."value" ' ),
182
+ 'pgsql ' , 'sqlite ' => new Expression (<<<SQL
183
+ {$ this ->wrap ('pulse_aggregates.value ' )} + "excluded"."value"
184
+ SQL ),
183
185
default => throw new RuntimeException ("Unsupported database driver [ {$ driver }] " ),
184
186
},
185
187
]
@@ -199,8 +201,12 @@ protected function upsertMin(array $values): int
199
201
[
200
202
'value ' => match ($ driver = $ this ->connection ()->getDriverName ()) {
201
203
'mariadb ' , 'mysql ' => new Expression ('least(`value`, values(`value`)) ' ),
202
- 'pgsql ' => new Expression ('least("pulse_aggregates"."value", "excluded"."value") ' ),
203
- 'sqlite ' => new Expression ('min("pulse_aggregates"."value", "excluded"."value") ' ),
204
+ 'pgsql ' => new Expression (<<<SQL
205
+ least( {$ this ->wrap ('pulse_aggregates.value ' )}, "excluded"."value")
206
+ SQL ),
207
+ 'sqlite ' => new Expression (<<<SQL
208
+ min( {$ this ->wrap ('pulse_aggregates.value ' )}, "excluded"."value")
209
+ SQL ),
204
210
default => throw new RuntimeException ("Unsupported database driver [ {$ driver }] " ),
205
211
},
206
212
]
@@ -220,8 +226,12 @@ protected function upsertMax(array $values): int
220
226
[
221
227
'value ' => match ($ driver = $ this ->connection ()->getDriverName ()) {
222
228
'mariadb ' , 'mysql ' => new Expression ('greatest(`value`, values(`value`)) ' ),
223
- 'pgsql ' => new Expression ('greatest("pulse_aggregates"."value", "excluded"."value") ' ),
224
- 'sqlite ' => new Expression ('max("pulse_aggregates"."value", "excluded"."value") ' ),
229
+ 'pgsql ' => new Expression (<<<SQL
230
+ greatest( {$ this ->wrap ('pulse_aggregates.value ' )}, "excluded"."value")
231
+ SQL ),
232
+ 'sqlite ' => new Expression (<<<SQL
233
+ max( {$ this ->wrap ('pulse_aggregates.value ' )}, "excluded"."value")
234
+ SQL ),
225
235
default => throw new RuntimeException ("Unsupported database driver [ {$ driver }] " ),
226
236
},
227
237
]
@@ -241,7 +251,9 @@ protected function upsertSum(array $values): int
241
251
[
242
252
'value ' => match ($ driver = $ this ->connection ()->getDriverName ()) {
243
253
'mariadb ' , 'mysql ' => new Expression ('`value` + values(`value`) ' ),
244
- 'pgsql ' , 'sqlite ' => new Expression ('"pulse_aggregates"."value" + "excluded"."value" ' ),
254
+ 'pgsql ' , 'sqlite ' => new Expression (<<<SQL
255
+ {$ this ->wrap ('pulse_aggregates.value ' )} + "excluded"."value"
256
+ SQL ),
245
257
default => throw new RuntimeException ("Unsupported database driver [ {$ driver }] " ),
246
258
},
247
259
]
@@ -264,8 +276,12 @@ protected function upsertAvg(array $values): int
264
276
'count ' => new Expression ('`count` + values(`count`) ' ),
265
277
],
266
278
'pgsql ' , 'sqlite ' => [
267
- 'value ' => new Expression ('("pulse_aggregates"."value" * "pulse_aggregates"."count" + ("excluded"."value" * "excluded"."count")) / ("pulse_aggregates"."count" + "excluded"."count") ' ),
268
- 'count ' => new Expression ('"pulse_aggregates"."count" + "excluded"."count" ' ),
279
+ 'value ' => new Expression (<<<SQL
280
+ ( {$ this ->wrap ('pulse_aggregates.value ' )} * {$ this ->wrap ('pulse_aggregates.count ' )} + ("excluded"."value" * "excluded"."count")) / ( {$ this ->wrap ('pulse_aggregates.count ' )} + "excluded"."count")
281
+ SQL ),
282
+ 'count ' => new Expression (<<<SQL
283
+ {$ this ->wrap ('pulse_aggregates.count ' )} + "excluded"."count"
284
+ SQL ),
269
285
],
270
286
default => throw new RuntimeException ("Unsupported database driver [ {$ driver }] " ),
271
287
}
0 commit comments