From de9be19db69a5814a7b98328cb43ceef9f8e9cf7 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 18 Jan 2024 11:31:47 +0900 Subject: [PATCH] docs: add note for PostgreSQL updateBatch() type error --- .../source/database/query_builder.rst | 7 +++++ .../source/database/query_builder/123.php | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 user_guide_src/source/database/query_builder/123.php diff --git a/user_guide_src/source/database/query_builder.rst b/user_guide_src/source/database/query_builder.rst index 5e6d54985a6c..0a79d158d0c3 100755 --- a/user_guide_src/source/database/query_builder.rst +++ b/user_guide_src/source/database/query_builder.rst @@ -1120,6 +1120,13 @@ The first parameter is an associative array of values, the second parameter is t .. note:: Since v4.3.0, the generated SQL structure has been Improved. + As a result, PostgreSQL may generate SQL errors if the column type is not + specified. In that case, specify the column name and its type as + ``::`` (e.g., ``updated_at::TIMESTAMP``). This feature + can be used since v4.4.5. + + .. literalinclude:: query_builder/123.php + Since v4.3.0, you can also use the ``onConstraint()`` and ``updateFields()`` methods: .. literalinclude:: query_builder/120.php diff --git a/user_guide_src/source/database/query_builder/123.php b/user_guide_src/source/database/query_builder/123.php new file mode 100644 index 000000000000..a594bda559d4 --- /dev/null +++ b/user_guide_src/source/database/query_builder/123.php @@ -0,0 +1,27 @@ + 'Derek Jones', + 'country' => 'Greece', + 'updated_at::TIMESTAMP' => '2023-12-02 18:47:52', + ], + [ + 'name' => 'Ahmadinejad', + 'country' => 'Greece', + 'updated_at::TIMESTAMP' => '2023-12-02 18:47:52', + ], +]; +$builder->updateBatch($data, 'name'); +/* + * Produces: + * UPDATE "db_user" + * SET + * "country" = _u."country", + * "updated_at" = _u."updated_at" + * FROM ( + * SELECT 'Greece' "country", 'Derek Jones' "name", '2023-12-02 18:47:52'::TIMESTAMP "updated_at" UNION ALL + * SELECT 'Greece' "country", 'Ahmadinejad' "name", '2023-12-02 18:47:52'::TIMESTAMP "updated_at" + * ) _u + * WHERE "db_user"."name" = _u."name" + */