D
D
Developereer2021-12-14 00:50:16
PostgreSQL
Developereer, 2021-12-14 00:50:16

How to specify schema when connecting to Postgresql nodejs?

Good afternoon!
There is an application on nodejs (express).
My question is: how can I specify the schema that I need to use when connecting to the database through pg (the default is public, I need another one)?
Or how do I even need to refer to a specific schema?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tomulevich, 2021-12-14
@phoinixrw

SET search_path TO <название нужной схемы>,public;
But this is a rather dumb decision if there are a lot of circuits.
And even more dumb, if there are tables with the same names in different schemas.
In my practice, I always specify the scheme in requests:

SELECT * FROM "myschema"."mytable";

UPDATE "catalog"."goods" SET "price" = 100 WHERE "id" = 10;

Etc.
And I advise you to always use double quotes when specifying the names of database objects, because:
- the name of the object can intersect with PostgreSQL keywords (KEYWORDS);
- if the name is used without quotes, then it is always given in lowercase;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question