I am trying to run a simple script on a simple PostgreSQL database with one table. When I use db.query('SELECT * FROM groups')
I get the error ERROR: relation "groups" does not exist at character 15
I ran the SQL in a Postgresql sandbox and it worked fine when I selected *, so I don't know what the problem here is. Here is the SQL Code
DROP TABLE IF EXISTS groups;
CREATE TABLE groups (
id serial PRIMARY KEY,
name varchar(255) NOT NULL,
birthPlace varchar(255) NOT NULL; );
INSERT INTO groups (name, birthPlace) VALUES
( 'Marco', 'Italy' ),
( 'Callum', 'Scotland' ),
( 'Bob, Ireland' );
And this is the javascript code where I use db.query
const db = require ('../dbConfig')
class Groups {
constructor(data){
this.id = data.id
this.name = data.name
this.birthPlace = data.birthPlace
}
static get all() {
return new Promise (async (resolve, reject) => {
try {
const groupData = await db.query('SELECT * FROM groups;')
const groups = groupData.rows.map(d => new Groups(d))
resolve(groups);
} catch (err) {
reject("Error retrieving groups")
}
})
}
}
module.exports = Groups;
I have read that this error can arise when quotes or capitals were used when the table is created but I haven't used either anywhere in my code. I hope these code snippets suffice, any help would be greatly appreciated.