2018-05-05 07:52
浏览 246


I am trying to fetch some data from postgress table using prepared statements

If I try with database.Get() everything is returned.


create table accounts
  id            bigserial not null
    constraint accounts_pkey
    primary key,
  identificator text      not null,
  password      text      not null,
  salt          text      not null,
  type          smallint  not null,
  level         smallint  not null,
  created_at    timestamp not null,
  updated       timestamp not null,
  expiry_date   timestamp,
  qr_key        text

Account struct:

type Account struct {
    ID            string `db:"id"`
    Identificator string `db:"identificator"`

    Password   string         `db:"password"`
    Salt       string         `db:"salt"`
    Type       int            `db:"type"`
    Level      int            `db:"level"`
    ExpiryDate time.Time      `db:"expiry_date"`
    CreatedAt  time.Time      `db:"created_at"`
    UpdateAt   time.Time      `db:"updated_at"`
    QrKey      sql.NullString `db:"qr_key"`

BTW i tried using ? instead of $1 & $2

stmt, err := database.Preparex(`SELECT * FROM accounts where identificator = $1 and type = $2`)

if err != nil {
accounts := []account.Account{}
err = stmt.Get(&accounts, "asd", 123)
if err != nil {

The error I get is

"errorMessage": "scannable dest type slice with \u003e1 columns (10) in result",

In the table there are no records I tried to remove all fields except the ID from Account (struct), however it does not work.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题