30

I'm using PostgreSQL 9.2.

Is there any way to get an output like,

Database : mydb, User : myUser

using a SELECT query?

3 Answers 3

47

By using the inbuilt System Information Functions

1.) Currently using database

   select current_database()

2.) Connected User

  select user

To get the desired output use either this

 select 'Database : ' ||current_database()||', '||'User : '|| user db_details

or

select format('Database: %s, User: %s',current_database(),user) db_details

Live Demo

Sign up to request clarification or add additional context in comments.

Comments

26

Check this part of the manual for more functions.

SELECT current_user,
       user,
       session_user,
       current_database(),
       current_catalog,
       version();

Comments

2

This shows the current database:

SELECT current_database();

This shows the current user:

SELECT current_user;

Comments

Your Answer

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