Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

BIT(N) columns don't include the N size in their types. #1672

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

Closed
alarbada opened this issue Jan 29, 2025 · 0 comments
Closed

BIT(N) columns don't include the N size in their types. #1672

alarbada opened this issue Jan 29, 2025 · 0 comments

Comments

@alarbada
Copy link

alarbada commented Jan 29, 2025

Setup:

CREATE TABLE bit_columns (
    bit1_col BIT(1),
    bit8_col BIT(8),
    bit16_col BIT(16),
    bit64_col BIT(64)
);

Example:

package main

import (
	"database/sql"
	"fmt"
	"log"

	_ "github.com/go-sql-driver/mysql"
)

func main() {
	db, err := sql.Open("mysql", "user:pass@tcp(127.0.0.1:3306)/dbname")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	rows, err := db.Query("SELECT * FROM bit_columns LIMIT 1")
	if err != nil {
		log.Fatal(err)
	}
	defer rows.Close()

	colTypes, err := rows.ColumnTypes()
	if err != nil {
		log.Fatal(err)
	}

	for _, colType := range colTypes {
		fmt.Println(colType.Name())
		fmt.Println(colType.DecimalSize())
		fmt.Println(colType.DatabaseTypeName())
		fmt.Println(colType.Length())
	}
}

Output:

bit1_col
0 0 false
BIT
0 false // <- why 0?
bit8_col
0 0 false
BIT
0 false // <- why 0?
bit16_col
0 0 false
BIT
0 false // <- why 0?
bit64_col
0 0 false
BIT
0 false // <- why 0?

I would expect that the Length() method would return the mysql specified bit size, or at least have some way to get that piece of information from *sql.ColumnType.

I'm using github.com/go-sql-driver/mysql v1.8.1.

@methane methane changed the title BUG: BIT(N) columns don't include the N size in their types. BIT(N) columns don't include the N size in their types. Jan 30, 2025
@go-sql-driver go-sql-driver locked and limited conversation to collaborators Jan 30, 2025
@methane methane converted this issue into discussion #1674 Jan 30, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant