Edit report at https://bugs.php.net/bug.php?id=81002&edit=1
ID: 81002
Updated by: cmb@php.net
Reported by: jeroen dot vanoort at webparking dot nl
Summary: Booleans are cast to integers when inserting records
Status: Open
Type: Bug
Package: PDO PgSQL
Operating System: Alpine
PHP Version: 8.0.5
Block user comment: N
Private report: N
New Comment:
This might be due the fix for bug #80892 which has recently been
reverted.
Previous Comments:
------------------------------------------------------------------------
[2021-04-30 11:04:31] jeroen dot vanoort at webparking dot nl
Description:
------------
It seems that, since using 8.0.5, booleans are cast to integers when inserting records into a
PostgreSQL database table. This causes PostgreSQL to throw an exception.
I use Laravel to do this, so it's not trivial for me to create a test script that's only
PHP. However, I did want to report this as it seems to be an unintentional breaking change.
How did I determine this isn't related to Laravel or PostgreSQL?
I tested my project with the php:8.0.3-fpm-alpine and php:8.0.3-fpm-alpine docker images. 8.0.3
works fine, 8.0.5 gives me the error below. I did not change the Laravel version, nor did I change
the PostgreSQL version.
The boolean true seems to have been casted to an integer in the SQL shown in the error message.
Test script:
---------------
ProductCategory::create([
'name' => 'FooBar',
'is_active' => true,
]);
ProductCategory is a Laravel model.
Expected result:
----------------
The record is added without errors or warnings.
Actual result:
--------------
Illuminate\Database\QueryException: SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column
"is_active" is of type boolean but expression is of type integer
LINE 1: ...e", "id", "updated_at", "created_at") values ($1, $2,
$3, $4...
^
HINT: You will need to rewrite or cast the expression. (SQL: insert into
"product_categories" ("name", "is_active", "id",
"updated_at", "created_at") values (FooBar, 1,
1eba993a-28f3-6596-9455-7e5293aad700, 2021-04-30 11:08:31, 2021-04-30 11:08:31))
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81002&edit=1