Skip to content

ColumnTypeLength method in stdlib/sql.go can not return the type length for 'varbit' type #2447

@DengChan

Description

@DengChan

Hi, I'm using pgx as a database/sql driver to build a pg client.
I try to use ColumnTypeLength function to get the type length for varbit type field, but it doesn't work.
I think it would be helpful to me if the code could be rewritten as below:

func (r *Rows) ColumnTypeLength(index int) (int64, bool) {
	fd := r.rows.FieldDescriptions()[index]

	switch fd.DataTypeOID {
	case pgtype.TextOID, pgtype.ByteaOID:
		return math.MaxInt64, true
	case pgtype.VarcharOID, pgtype.BPCharArrayOID:
		return int64(fd.TypeModifier - varHeaderSize), true
	case pgtype.VarbitOID:
		return int64(fd.TypeModifier), true
	default:
		return 0, false
	}
}

If you don't mind, I could submit a PR~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions