0

I am trying to get up and running with pg-promise, but it thinks my database table doesn't exist, and I am not sure why.

app.js

require("dotenv").config(); const express = require("express"); const { db } = require("./database.js"); const app = express(); const PORT = 8080; app.get("/", (req, res) => { db.one("SELECT * FROM test WHERE id = $1", 1) .then((record) => { console.log(record); res.send("Success"); }) .catch((error) => { console.log(error); res.send("Error"); }); }); app.listen(PORT, () => { console.log(`Example app listening at http://localhost:${PORT}`); }); 

.env

DATABASE_CONNECTION=postgres://adamzerner:<iputmyrealpasswordhere>@localhost:5432/calibration-training 

database.js

const pgp = require("pg-promise")(); const db = pgp(process.env.DATABASE_CONNECTION); module.exports = { pgp, db }; 

Then when I hit the endpoint, this is what gets logged:

code/calibration-training-api [master●] » yarn start yarn run v1.22.10 $ node app.js Example app listening at http://localhost:8080 error: relation "test" does not exist at Parser.parseErrorMessage (/Users/adamzerner/code/calibration-training-api/node_modules/pg-protocol/dist/parser.js:287:98) at Parser.handlePacket (/Users/adamzerner/code/calibration-training-api/node_modules/pg-protocol/dist/parser.js:126:29) at Parser.parse (/Users/adamzerner/code/calibration-training-api/node_modules/pg-protocol/dist/parser.js:39:38) at Socket.<anonymous> (/Users/adamzerner/code/calibration-training-api/node_modules/pg-protocol/dist/index.js:11:42) at Socket.emit (node:events:390:28) at addChunk (node:internal/streams/readable:315:12) at readableAddChunk (node:internal/streams/readable:289:9) at Socket.Readable.push (node:internal/streams/readable:228:10) at TCP.onStreamRead (node:internal/stream_base_commons:199:23) { length: 103, severity: 'ERROR', code: '42P01', detail: undefined, hint: undefined, position: '15', internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'parse_relation.c', line: '1384', routine: 'parserOpenTable' } 

But looking in Beekeeper Studio, it shows that the table exists with a record, and the SQL query works there.

enter image description here

public.test doesn't work either, nor does calibration-training.public.test, or Test or "Test" or "test".

psql also shows that the table exists:

code/calibration-training-api [master●] » psql psql (14.0) Type "help" for help. adamzerner=# \c calibration-training You are now connected to database "calibration-training" as user "adamzerner". calibration-training=# \dt List of relations Schema | Name | Type | Owner --------+------+-------+------------ public | Test | table | adamzerner (1 row) 
1
  • I didn't implement any AI in pg-promise, so it cannot think, sorry (the author). Commented Oct 23, 2021 at 6:21

1 Answer 1

1

That's because test and "Test" are 2 different table names.

Check camel-case + escaping SQL names in PostgreSQL ;)

Sign up to request clarification or add additional context in comments.

1 Comment

Oh wow, I could have sworn I had tried "Test". Thanks for the assist! (I'm new to postgres.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.