TransWikia.com

Getting active PostgreSQL connection username when stored through authentication configuration in QGIS 3.16

Geographic Information Systems Asked on July 26, 2021

How do I get the username on the current layer PostGIS in QGIS 3.16.2-Hannover?
We tried examples: Getting active PostgreSQL connection username when stored through authentication configuration in QGIS 3, but they don’t work.

When running this script, variable username is empty:

layer = iface.activeLayer()
provider = layer.dataProvider()
username = QgsDataSourceUri(provider.dataSourceUri()).username()
print (username)

This is result of provider.dataSourceUri()):

<QgsDataSourceUri: dbname=’postgres’ host= localhost port=5432
sslmode=disable key=’id’ srid=4326 type=Point
checkPrimaryKeyUnicity=’1′ table="locations"."airlines" (geom)>

The value of the username is missing, the question is how to get the username for the current layer?

One Answer

You can select your PostgreSQL user using the 'PostgreSQL Execute SQL' command in the Processing toolbox.

Query:

SELECT user;

enter image description here

Answered by Encomium on July 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP