2

Is it possible to use project variable in the PostgreSQL database connection in QGIS?

Usecase: Each user will set his/her db_user variable as part of the project. Once the project is shared among users, everybody will access the PostgreSQL database using assigned user.

Talking about project variables: I mean those, which are to be set in Project -> Properties and ɛ Variables

3
  • 1
    Description not complete (cut for unknown reason). Edit, plz. Commented Jun 6, 2020 at 21:11
  • Sorry about that, should be better now. Commented Jun 7, 2020 at 6:54
  • I think you should look at PG Services file. postgresql.org/docs/11/libpq-pgservice.html Commented Jun 7, 2020 at 7:55

1 Answer 1

2

QGIS variables are effective after you open layers sources from QGIS project not before so it's not possible to provide connexion information here to my knowledge.

You should use PostgreSQL Service connection file instead. It avoids storing database informations within the project and instead use the configuration file to provide connection informations.

See official QGIS documentation https://docs.qgis.org/3.10/en/docs/user_manual/managing_data_source/opening_data.html#postgresql-service-connection-file and official PostgreSQL doc https://www.postgresql.org/docs/12/libpq-pgservice.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.