Skip to content

Commit ecfb48e

Browse files
committed
docs: add note for PostgreSQL updateBatch() type error
1 parent 46346e6 commit ecfb48e

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

user_guide_src/source/database/query_builder.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,13 @@ The first parameter is an associative array of values, the second parameter is t
11201120

11211121
.. note:: Since v4.3.0, the generated SQL structure has been Improved.
11221122

1123+
As a result, PostgreSQL may generate SQL errors if the column type is not
1124+
specified. In that case, specify the column name and its type as
1125+
``<column_name>::<type>`` (e.g., ``updated_at::TIMESTAMP``). This feature
1126+
can be used since v4.4.5.
1127+
1128+
.. literalinclude:: query_builder/123.php
1129+
11231130
Since v4.3.0, you can also use the ``onConstraint()`` and ``updateFields()`` methods:
11241131

11251132
.. literalinclude:: query_builder/120.php
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
$data = [
4+
[
5+
'name' => 'Derek Jones',
6+
'country' => 'Greece',
7+
'updated_at::TIMESTAMP' => '2023-12-02 18:47:52',
8+
],
9+
[
10+
'name' => 'Ahmadinejad',
11+
'country' => 'Greece',
12+
'updated_at::TIMESTAMP' => '2023-12-02 18:47:52',
13+
],
14+
];
15+
$builder->updateBatch($data, 'name');
16+
/*
17+
* Produces:
18+
* UPDATE "db_user"
19+
* SET
20+
* "country" = _u."country",
21+
* "updated_at" = _u."updated_at"
22+
* FROM (
23+
* SELECT 'Greece' "country", 'Derek Jones' "name", '2023-12-02 18:47:52'::TIMESTAMP "updated_at" UNION ALL
24+
* SELECT 'Greece' "country", 'Ahmadinejad' "name", '2023-12-02 18:47:52'::TIMESTAMP "updated_at"
25+
* ) _u
26+
* WHERE "db_user"."name" = _u."name"
27+
*/

0 commit comments

Comments
 (0)