bun icon indicating copy to clipboard operation
bun copied to clipboard

DatabaseTypeName missing with pgdriver

Open knightjdr opened this issue 1 year ago • 0 comments

I'm having to implement some custom scanning logic and being able to determine the column type is needed. If I run the following I am not getting any value returned for DatabaseTypeName and just interface{} for ScanType:

ctx := context.Background()
rows, err := db.QueryContext(ctx, "SELECT name FROM my_table LIMIT 1;")
if err != nil {
   return err
}
defer rows.Close()

columnTypes, _ := rows.ColumnTypes()
for _, columnType := range columnTypes {
   fmt.Println(columnType.Name(), columnType.DatabaseTypeName(), columnType.ScanType())
}

// prints: name  interface {}

The SQL reference docs say for DatabaseTypeName:

If an empty string is returned, then the driver type name is not supported. Consult your driver documentation for a list of driver data types. Length specifiers are not included. Common type names include "VARCHAR", "TEXT", "NVARCHAR", "DECIMAL", "BOOL", "INT", and "BIGINT".

I'm using pgdriver. The column types I have tried returning are character varying, smallint, and boolean. I cannot find any further clarification in the documentation on why these aren't supported.

DatabaseTypeName is returned when I switch to pgx driver, however.

knightjdr avatar Jan 23 '24 15:01 knightjdr