如何使用PostgreSQL中的选择获取当前数据库和用户名 [英] how to get current database and user name using a select in postgresql
本文介绍了如何使用PostgreSQL中的选择获取当前数据库和用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 PostgreSQL 9.2
,有什么方法可以通过 select 查询获得如下所示的输出吗?
I am using PostgreSQL 9.2
, Is there any way to get an output like below using a select query ?
数据库:mydb,用户:myUser
Database : mydb, User : myUser
推荐答案
通过使用内置的系统信息功能
1。)当前正在使用数据库
1.) Currently using database
select current_database()
2。)已连接的用户
select user
要获得所需的输出,请使用此
To get the desired output use either this
select 'Database : ' ||current_database()||', '||'User : '|| user db_details
或
select format('Database: %s, User: %s',current_database(),user) db_details
这篇关于如何使用PostgreSQL中的选择获取当前数据库和用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文