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

Erro dialect mssql witch NEXT in the FETCH #811

Open
chapzin opened this issue Apr 4, 2023 · 1 comment · May be fixed by #1009
Open

Erro dialect mssql witch NEXT in the FETCH #811

chapzin opened this issue Apr 4, 2023 · 1 comment · May be fixed by #1009

Comments

@chapzin
Copy link

chapzin commented Apr 4, 2023

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
Copy link
Author

chapzin commented Apr 4, 2023

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
}

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

Successfully merging a pull request may close this issue.

1 participant