如何在PostgreSQL中使用`select`获取当前数据库和用户名? [英] How to get current database and user name with `select` in PostgreSQL?
本文介绍了如何在PostgreSQL中使用`select`获取当前数据库和用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是 PostgreSQL 9.2
.
有什么办法可以得到类似的输出,
Is there any way to get an output like,
数据库:mydb,用户:myUser
Database : mydb, User : myUser
使用 select 查询?
推荐答案
通过使用内置的 系统信息功能
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中使用`select`获取当前数据库和用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文