label SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect critical value: 'buy_amt * 0.00097812555575316' for column 'price' at row 1 error

Asked 2 years ago, Updated 2 years ago, 48 views

I want to update the entire data, but I have to calculate the margin rate at the purchase price and divide it by the exchange rate, but there is a data format errorㅠ;;

SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect decimal value: 'buy_amt * 0.00097812555575316' for column 'prod' at row 1 (SQL: update prod set value = 10, price = buy_amt * 0.00097812555575316 )

What's wrong with turning the sql in the error code to run properly

use DB;

DB::update("update prod set value = ?, price = ?,  ",
            [
                $datas["value"],
                "buy_amt * ".(1+($datas["value"]/100))/$datas["price"],
            ]);

laravel php

2022-09-22 19:11

1 Answers

So you want mysql to do the math himself? You should use DB::raw()

If you refer to this case, you can roughly do this.

DB::table('prod')->update([
    'value' => $datas["value"],
    'price' => DB::raw("buy_amt * ".(1+($datas["value"]/100))/$datas["price"])
]);

PS: Personally, I don't recommend having mysql compute. It would be faster and smoother (whether PHP or mysql) to get the calculations needed from the source before sending the update.


2022-09-22 19:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.