Skip to content
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

DatabaseTypeName missing with pgdriver #947

Open
knightjdr opened this issue Jan 23, 2024 · 0 comments
Open

DatabaseTypeName missing with pgdriver #947

knightjdr opened this issue Jan 23, 2024 · 0 comments

Comments

@knightjdr
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant