Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when inserting boolean values #208

Open
bpastukh opened this issue Jan 22, 2024 · 2 comments
Open

Error when inserting boolean values #208

bpastukh opened this issue Jan 22, 2024 · 2 comments

Comments

@bpastukh
Copy link

Hi, i'm facing following exception when executing insert with bool value when columns is of UInt8 type after upgrading to v1.5.2.
After debug i've noticed that false is converted to 'false'.

In Statement.php line 183:

[ClickHouseDB\Exception\QueryException (400)]
HttpCode:400 ; ;Code: 6, e.displayText() = DB::Exception: Cannot parse string 'false' as UInt8: syntax error at begin of string. Note: there are toUInt8OrZero and toUInt8OrNull functions, which returns zer
o/NULL instead of throwing exception.: while executing 'FUNCTION CAST(assumeNotNull(_dummy_0) :: 2, 'UInt8' :: 1) -> cast(assumeNotNull(_dummy_0), 'UInt8') UInt8 : 4' (version 21.2.5.5 (official build))

Same problem is with Bool type (Type bool is internally stored as UInt8.) https://clickhouse.com/docs/en/sql-reference/data-types/boolean.

I suspect this commit to be the reason of the problem c8c9006

@mrceperka
Copy link

Got the same problem

@MakarMS
Copy link

MakarMS commented Mar 17, 2024

Hi, i'm facing following exception when executing insert with bool value when columns is of UInt8 type after upgrading to v1.5.2. After debug i've noticed that false is converted to 'false'.

In Statement.php line 183:

[ClickHouseDB\Exception\QueryException (400)] HttpCode:400 ; ;Code: 6, e.displayText() = DB::Exception: Cannot parse string 'false' as UInt8: syntax error at begin of string. Note: there are toUInt8OrZero and toUInt8OrNull functions, which returns zer o/NULL instead of throwing exception.: while executing 'FUNCTION CAST(assumeNotNull(_dummy_0) :: 2, 'UInt8' :: 1) -> cast(assumeNotNull(_dummy_0), 'UInt8') UInt8 : 4' (version 21.2.5.5 (official build))

Same problem is with Bool type (Type bool is internally stored as UInt8.) https://clickhouse.com/docs/en/sql-reference/data-types/boolean.

I suspect this commit to be the reason of the problem c8c9006

Hi. The implicitness when working with Bool type has been removed. If your column is declared as Int8, you should pass an integer, not a boolean to it, hoping for implicit type casting. If you want to pass a boolean type from PHP, then you need to use the Bool type for your column, regardless of its internal implementation in the database. This removes the implicit and makes the code more maintainable.

I agree that this should not have been in the patch version, but the change itself is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants