Insert multiple values into a column of a table in PostgreSQL

50 Views Asked by At

Suppose I want to insert multiple rows into a table in PostregSQL. The example below shows how to do that using only one row, but what if I want to insert several rows? How to do that? If I have several names with the same email?

const text = 'INSERT INTO users(name, email) VALUES($1, $2) RETURNING *'
const values = ['brianc', '[email protected]']

// promise
client
  .query(text, values)
  .then(res => {
    console.log(res.rows[0])
    // { name: 'brianc', email: '[email protected]' }
  })
  .catch(e => console.error(e.stack))

0

There are 0 best solutions below