Johnathan Douglas 2023-07-07 19:41:05 -03:00
parent 15d76cbde6
commit 333cd6057f
1 changed files with 10 additions and 46 deletions

View File

@ -9,27 +9,14 @@ class UpdateMassive2
/** /**
* *
* update test as t set * update transactions as t
* column_a = c.column_a, * set date = c.date,
* column_c = c.column_c * value = c.value
* from (values * from (
* ('123', 1, '---'), * values (1, '2023-01-05 00:00:00'::timestamp, 23.44),
* ('345', 2, '+++') * (2, '2023-01-03 00:00:00'::timestamp, 23.44)
* ) as c(column_b, column_a, column_c) * ) as c(id, date, value)
* where c.column_b = t.column_b; * where t.id = c.id;
*
*
* UPDATE transactions
* SET updated_at = CASE id
* WHEN 1 THEN '2019-01-15 10:00:00'::date
* WHEN 2 THEN '2019-01-16 11:00:00'::date
* WHEN 3 THEN '2019-01-17 12:00:00'::date
* END
* WHERE id IN (1, 2, 3);
*
* update transactions set updated_at = '2019-01-15 10:00:00' where id = 1
* update transactions set updated_at = '2019-01-16 10:00:00' where id = 2
* update transactions set updated_at = '2019-01-17 10:00:00' where id = 3
* *
* @param string $table * @param string $table
* @param string $primaryKeyName * @param string $primaryKeyName
@ -40,7 +27,7 @@ class UpdateMassive2
* [ * [
* "primary_key" => 200576 * "primary_key" => 200576
* "columns" => array:1 [ * "columns" => array:1 [
* "transactions_banks.coupon_code" => "2001462387" * "coupon_code" => "2001462387"
* ] * ]
* ] * ]
* ] * ]
@ -49,29 +36,6 @@ class UpdateMassive2
*/ */
public function apply(string $table, string $primaryKeyName, array $config): void public function apply(string $table, string $primaryKeyName, array $config): void
{ {
/**
* update test as t set
* column_a = c.column_a,
* column_c = c.column_c
* from (values
* ('123', 1, '---'),
* ('345', 2, '+++')
* ) as c(column_b, column_a, column_c)
* where c.column_b = t.column_b;
*
*
* update transactions as t
* set date = c.date,
* value = c.value
* from (
* values (1, '2023-01-05 00:00:00'::timestamp, 23.44),
* (2, '2023-01-03 00:00:00'::timestamp, 23.44)
* ) as c(id, date, value)
* where t.id = c.id;
*
*/
$valuesSqls = []; $valuesSqls = [];
$columns = $config[0]['columns']; $columns = $config[0]['columns'];