Skip to content Skip to sidebar Skip to footer

Unable To Query Postgresql Database In Nodejs Using Pg-promise - "relation Does Not Exist"

I'm trying to get pg-promise working in NodeJS to allow me to connect to my PostgreSQL database. Both node and postgre are running in a codeanywhere node box running Ubuntu. Here'

Solution 1:

The error is telling you that there is no users table in your database. You need to create the table before you can select from it. Remember, the table name is case sensitive so if you created a Users table, your query won't work.

CREATETABLE Users (...);
SELECT*FROM users; -- this will cause an error

You should try connecting to your database using psql -d users (users in this case is the name of your database, not to be confused with your table of the same name) on the command line. From there you can write queries to test them independently from your application code. In case you're having trouble connecting to your users database, you can always connect to the default database with psql and type \l or \list to list all databases postgres knows about.

Note that Postgres itself has a built in database named postgres that has its own users table to manage access control to other databases. You can tell which database you're connected to in psql by looking at the command prompt; If it says postgres= then you're in the postgres database, not your own.

Post a Comment for "Unable To Query Postgresql Database In Nodejs Using Pg-promise - "relation Does Not Exist""