获取我的 postgresql db 版本?

And*_*oll 5 sqlite postgresql postgresql-9.5

在 SQlite 上,我可以进行查询,PRAGMA user_version;如果需要,我也可以设置版本。postgres 中有什么东西可以做同样的事情吗?

我试过了,select version()但这得到了 postgres 的文字版本,而不是自定义集版本。

作为更新:我研究了对数据库的评论。也许这可能是解决方案...评论文档

kli*_*lin 5

您可以设置自定义配置参数。参数名称必须包含点,例如:

set my.version to 4;
select current_setting('my.version') as version;

 version 
---------
 4
(1 row)
Run Code Online (Sandbox Code Playgroud)

以这种方式定义的参数对于当前会话来说是本地的。如果您想为所有会话定义参数的默认值,您可以将其添加到配置文件postgresql.conf(对于服务器中的所有数据库)。或者,可以在命令中设置数据库的默认值:

set my.version to 4;
alter database my_database set my.version from current;
Run Code Online (Sandbox Code Playgroud)

也可以看看: