Skip to content

RFC: Parse TINYINT(1) as bool #1453

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

Open
methane opened this issue Jun 22, 2023 · 4 comments
Open

RFC: Parse TINYINT(1) as bool #1453

methane opened this issue Jun 22, 2023 · 4 comments
Milestone

Comments

@methane
Copy link
Member

methane commented Jun 22, 2023

MySQL doesn't have actual bool type. Boolean is alias of TINYINT(1).

Using TINYINT(1) for regular integer is not so common.
How about treating TINYINT(1) as bool for better experience?

var b any
db.QueryRow("SELECT true").Scan(&b) // b is bool(true), not int64(1).
@methane methane added this to the v1.8.0 milestone Jun 22, 2023
@dolmen
Copy link
Contributor

dolmen commented Oct 17, 2023

CREATE TABLE tbl (x TINYINT(1));
INSERT INTO tbl VALUES (-128),(127);
SELECT * FROM tbl;
+------+
| x    |
+------+
| -128 |
|  127 |
+------+
2 rows in set (0,33 sec)

@methane
Copy link
Member Author

methane commented Oct 19, 2023

OK. Assuming TINYINT(1) is bool is not 100% safe.
I think we should keep status quo.

@methane
Copy link
Member Author

methane commented Mar 17, 2025

Using TINYINT(1) for Boolean is MySQL's spec.
I am thinking about adding tinyint1isbool option. It changes behavior for signed tinyint(1) like:

  • DatabaseTypeName() is Boolean
  • ScanType() is bool
  • Scan(*any) returns bool

@kirs
Copy link

kirs commented Mar 17, 2025

I would be very supportive of having an option like tinyint1isbool, since as of today there's no good way to get Length() of a column in a result set, and it's been really tricky in my app's use case to figure if it's boolean or an actual tinyint.

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