0

I'm developing a nodejs project with a postgresql-db. I've created a table called 'UserAsanas'. It's definitely there, I've checked and re-checked.

But when I try to multi-row insert it keeps telling me the following:

error: relation "UserAsanas" does not exist

const cs =  pgp.helpers.ColumnSet(['UserID', 'AsanaID', 'RoutineID'], { table: 'UserAsanas' });

const values = [{UserID: 1, AsanaID: 2,RoutineID: 1}, {UserID: 1, AsanaID: 33,RoutineID: 1}];

const multi =  pgp.helpers.insert(values, cs)+ ' RETURNING id';
// INSERT INTO "UserAsanas"("UserID","AsanaID","RoutineID") VALUES(1,2,1),(1,33,1) RETURNING id

db.none(multi).then(data=> {
  res.status(201)
})
.catch( err => {
   return next(err)
})
vitaly-t
  • 24,279
  • 15
  • 116
  • 138
ClaraG
  • 322
  • 2
  • 14
  • 2
    SQL identifiers (like table and column names) aren't case-sensitive by default -- is it possible that you have a table "userasanas" that you're trying to access as "UserAsanas"? Or vice versa? – jmelesky May 09 '19 at 22:08
  • 1
    @jmelesky I was going to say the same. It is either that, or he created the table in a non-default schema. – vitaly-t May 09 '19 at 23:06
  • Thanks, the table is called UserAsanas for sure, and I am able to insert data just by `db.one('INSERT INTO UserAsanas (UserID, AsanaID, RoutineID) VALUES (1,2,3) RETURNING ID').then(data=> { res.status(201).send(`Asana added to Routine ${routineId} with ID: ${data.id}`) })` – ClaraG May 10 '19 at 05:55
  • just to add more info, Im using "pg-promise": "^8.6.5" and "bluebird": "^3.5.4" – ClaraG May 10 '19 at 06:06

1 Answers1

-1

yep. all small letters and it works like a treat!

const single =  pgp.helpers.insert({userid: 1, asanaid: 2,routineid: 1}, null,  'userasanas' );
const multi =  pgp.helpers.insert([{userid: 1, asanaid: 5,routineid: 1}, {userid: 1, asanaid: 4,routineid: 1}], ['userid', 'asanaid', 'routineid'],  'userasanas' );
ClaraG
  • 322
  • 2
  • 14
  • This means you declared the table incorrectly, using mixed case, but without wrapping it into `""`. Correct your table + columns declaration, using `""`, and that's it. This got nothing to do with `pg-promise`, and this answer is not a good advise. – vitaly-t May 10 '19 at 16:37