I'm trying to connect to my postgres database.
Everything is working fine, but in my database I've got 2 schemas. One of them is created by default by PgAdmin
(public
), and the second one, ZTB
, which I have created.
When I connect to my database using NodeJS, it by default connects to the "public
" schema, and therefore I cannot query tables from "ZTB".
Is there any solution to switch the current working schema in the NodeJS server?
Regards
PostgreSQL is a really popular, free, open-source relational database. The node-postgres module is a widely-employed and matured module that bridges Node.js to PostgreSQL. In this article, we've set up a PostgreSQL database and developed basic CRUD functionality through a simple Node.js script.
Basically, the default connection string in the PostgreSQL database server will have a database name. But if there is no argument for specifying the schema name, there is a solution for that. Just execute a certain command after successfully logging in to the PostgreSQL database server. This article will demonstrate how to do it.
After successfully logging in to the PostgreSQL command console, just check the default current active working schema. Read the article with the title of ‘How to Check Default Current Active Working Schema in PostgreSQL Database Server’ in this link for a reference. But by default, the current active schema is the public schema.
In order to achieve the purpose for switching to another schema from the default public schema, just execute the command using search_path. The following is the demonstration where everything starts from the logging access as follows : Accessing the PostgreSQL Database Server from the command line by typing the following command
I found solution myself - client.query("SET search_path TO 'ZTB';");
did the job exactly as @a_horse_with_no_name said later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With