mgutz / dat

Go Postgres Data Access Toolkit
Other
612 stars 62 forks source link

SelectDoc with no results returns database error #24

Closed nickmarx12345678 closed 9 years ago

nickmarx12345678 commented 9 years ago

DB

-- SQL Setup
CREATE TABLE product_prototypes (
  id bigserial PRIMARY KEY,
  name text NOT NULL
);

Running (select with no results)

package main

import "gopkg.in/mgutz/dat.v1/sqlx-runner"

func main() {
    db := runner.NewDBFromString("postgres", "postgres://localhost/dat_test?sslmode=disable")

    b, err := db.SelectDoc("id, name").From("product_prototypes").QueryJSON()
    if err != nil {
        panic(err)
    }

    println(string(b))
}

returns a DB error ErrNoRows == errors.New("sql: no rows in result set") http://golang.org/pkg/database/sql/

Is this intentional? Would think you'd want to not perform the scan if the result set was empty

mgutz commented 9 years ago

That is by design. It's consistent with the behavior of Go's sql package.