-1

pg-promise successfully inserted an row into table, but not showing insert return record. If i not use returning then all is fine. if using then error occurs.

const createEMP = async (req, res, next) => {
try{
   let user = await db.none("insert into emp (name, salary, joindate) 
   values ( ${name}, ${salary}, ${joindate}) returning * ", req.body)

            res.status(200).json({
                user,
                "message": "new user created"
            })
        }
        catch(error) {next(error)}
    }

In postman, it shows a very long page of error. It says: <pre>QueryResultError: No return data was expected.<br>.....

jian
  • 4,119
  • 1
  • 17
  • 32
  • Doesn't [API for the method](http://vitaly-t.github.io/pg-promise/Database.html#none) explain it clearly what the method expects as a result? - `expects no data to be returned`. Just read the documentation, and follow it. – vitaly-t Aug 01 '21 at 15:06

1 Answers1

0

change from db.none to db.one Work.

jian
  • 4,119
  • 1
  • 17
  • 32