uptrace / bun

SQL-first Golang ORM
https://bun.uptrace.dev
BSD 2-Clause "Simplified" License
3.65k stars 221 forks source link

DatabaseTypeName missing with pgdriver #947

Open knightjdr opened 8 months ago

knightjdr commented 8 months ago

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.