Skip to content

Commit fbacb30

Browse files
committed
refactor: use CAST(expression AS type) instead of ::type
1 parent fa2e073 commit fbacb30

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

system/Database/Postgre/Builder.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ protected function _updateBatch(string $table, array $keys, array $values): stri
353353
array_map(
354354
static fn ($key, $value) => $key . ($value instanceof RawSql ?
355355
' = ' . $value :
356-
' = ' . $alias . '.' . $that->cast($value, $that->getFieldType($table, $key))),
356+
' = ' . $that->cast($alias . '.' . $value, $that->getFieldType($table, $key))),
357357
array_keys($updateFields),
358358
$updateFields
359359
)
@@ -375,7 +375,8 @@ static function ($key, $value) use ($table, $alias, $that) {
375375
return $value;
376376
}
377377

378-
return $table . '.' . $value . ' = ' . $alias . '.' . $that->cast($value, $that->getFieldType($table, $value));
378+
return $table . '.' . $value . ' = '
379+
. $that->cast($alias . '.' . $value, $that->getFieldType($table, $value));
379380
},
380381
array_keys($constraints),
381382
$constraints
@@ -413,7 +414,7 @@ static function ($key, $value) use ($table, $alias, $that) {
413414
*/
414415
private function cast($expression, ?string $type): string
415416
{
416-
return ($type === null) ? $expression : $expression . '::' . strtoupper($type);
417+
return ($type === null) ? $expression : 'CAST(' . $expression . ' AS ' . strtoupper($type) . ')';
417418
}
418419

419420
/**

0 commit comments

Comments
 (0)