Skip to content

Commit

Permalink
docs: add note for PostgreSQL updateBatch() type error
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jan 18, 2024
1 parent 407846f commit de9be19
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions user_guide_src/source/database/query_builder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
``<column_name>::<type>`` (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
Expand Down
27 changes: 27 additions & 0 deletions user_guide_src/source/database/query_builder/123.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

$data = [
[
'name' => '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"
*/

0 comments on commit de9be19

Please sign in to comment.