uptrace / bun

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

Erro dialect mssql witch NEXT in the FETCH #811

Open chapzin opened 1 year ago

chapzin commented 1 year ago

in import i use:

_ "github.com/denisenkom/go-mssqldb"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect/mssqldialect"

function i use:

func (i *Inventario) GetFistThreeItens(db *bun.DB, cnpj string, ano int) ([]models.Inventario, error) {
    var itens []models.Inventario
    err := db.NewSelect().Model(&itens).Where("cnpj = ? and ano = ?", cnpj, ano).Limit(3).Scan(context.Background())
    if err != nil {
        return nil, err
    }
    return itens, nil
}

recive erro return: mssql.Error: mssql: Invalid usage of the option NEXT in the FETCH statement

my microsoft sql server 2017

chapzin commented 1 year ago

problem fix if use Order before Limit look now

func (i *Inventario) GetFistThreeItens(db *bun.DB, cnpj string, ano int) ([]models.Inventario, error) {
    var itens []models.Inventario
    err := db.NewSelect().Model(&itens).Where("cnpj = ? and ano = ?", cnpj, ano).Order("id").Limit(3).Scan(context.Background())
    if err != nil {
        return nil, err
    }
    return itens, nil
}