Scan error on column index 8, name 'replicated': Scan not supported, storing driver.Value of type uint8 as type **bool

PHPz
Release: 2024-02-12 15:15:07
forward
857 people have browsed it

列索引 8 上的扫描错误,名称“replicated”:不支持扫描,将 driver.Value 类型 uint8 存储为 **bool 类型

Question content

I use sqlx to select PostgreSQL boolan[] into a Golang structure, where the target structure value is []*bool.

type App struct {
    ApplicationID string  `db:"application_id"`
    Name          string  `db:"name"`
    Description   string  `db:"description"`
    Replicated    []*bool `db:"replicated"`
}

var apps []App

err := trx.Select(&apps, "Select * From my_function()")
Copy after login

The error returned is: sql: Scan error on column index 3, name "replicated": Scan is not supported, driver.Value type []uint8 is stored as type *[]*bool

I've looked around but haven't found a solution yet. Any help would be greatly appreciated!

Solution

You can only scan content that implements the .Scanner interface. You can define the structure as

import "github.com/lib/pq"

type App struct {
    ApplicationID string  `db:"application_id"`
    Name          string  `db:"name"`
    Description   string  `db:"description"`
    Replicated    pq.BoolArray `db:"replicated"`
}
Copy after login

where pq.BoolArray is []bool, or if you really need it to be []*bool you can create your own type

type BoolArray []*bool
Copy after login

Then copy the code from here https://github. com/lib/pq/blob/2a217b94f5ccd3de31aec4152a541b9ff64bed05/array.go#L76 and modify as needed

The above is the detailed content of Scan error on column index 8, name 'replicated': Scan not supported, storing driver.Value of type uint8 as type **bool. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!