Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS Postgres switch working schema


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

like image 436
Rafael Avatar asked Jan 27 '18 12:01

Rafael


People also ask

What is node PostgreSQL?

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.

How to get the schema name of a PostgreSQL database?

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.

How to check default current active working schema in PostgreSQL?

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.

How to switch to another schema from the default 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


1 Answers

I found solution myself - client.query("SET search_path TO 'ZTB';"); did the job exactly as @a_horse_with_no_name said later.

like image 98
Rafael Avatar answered Nov 03 '22 00:11

Rafael