uptrace / bun

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

ParseInt Error #1005

Closed boskiv closed 3 days ago

boskiv commented 4 months ago

Model

type TickIndexDto struct {
    bun.BaseModel `bun:"table:tick_indexes"`
    Timestamp     int64     `bun:",notnull"`
    TickIndex     int64     `bun:",notnull"`
    Window        int64     `bun:",notnull"`
    Sma           float64   `bun:",notnull"`
    CreatedAt     time.Time `bun:",nullzero,notnull,default:current_timestamp"`
}

Method

func (r *repository) GetBucket(filter *tickIndex.GetTickIndexURI) ([]*models.TickIndexBucket, error) {
    tickIndexList := make([]*models.TickIndexBucket, 0)

    query := r.client.
        NewSelect().
        Table(fmt.Sprintf("tick_indexes_%s", filter.TimeFrame)).
        Where("\"window\" = ?", filter.Window).
        Limit(filter.Limit).
        Order("bucket ASC")

    if filter.StartTime != 0 {
        query.Where("extract (epoch from bucket) * 1000 >= ?", filter.StartTime)
    }
    if filter.EndTime != 0 {
        query.Where("extract (epoch from bucket) * 1000 <= ?", filter.EndTime)
    }

    if err := query.Scan(context.Background(), &tickIndexList); err != nil {
        r.logger.WithError(err).Error("GetBucket")
        return nil, err
    }

    return tickIndexList, nil
}

Table DDL

create table public.tick_indexes (
  timestamp bigint not null,
  tick_index bigint not null,
  window bigint not null,
  sma double precision not null,
  created_at timestamp with time zone not null default CURRENT_TIMESTAMP
);
create index tick_indexes_created_at_idx on tick_indexes using btree (created_at);

Error

[bun]  11:32:19.172   SELECT               94.896ms  SELECT * FROM "tick_indexes_1m" WHERE ("window" = '60') ORDER BY "bucket" ASC LIMIT 100     *fmt.wrapError: sql: Scan error on column index 2, name "tick_index": strconv.ParseInt: parsing "18.0000000000000000": invalid syntax 
github-actions[bot] commented 1 week ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed.