Skip to content

RFC: Parse TINYINT(1) as bool #1453

Open
@methane

Description

@methane

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).

Activity

added this to the v1.8.0 milestone on Jun 22, 2023
dolmen

dolmen commented on Oct 17, 2023

@dolmen
Contributor
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

methane commented on Oct 19, 2023

@methane
MemberAuthor

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

methane

methane commented on Mar 17, 2025

@methane
MemberAuthor

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

kirs commented on Mar 17, 2025

@kirs

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.

modified the milestones: v1.8.0, v1.10.0 on Apr 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @dolmen@methane@kirs

        Issue actions

          RFC: Parse `TINYINT(1)` as `bool` · Issue #1453 · go-sql-driver/mysql