在 PostgreSQL 中舍入一个版本

round a version in PostgreSQL

我需要对版本列进行四舍五入,Round() 适用于小数,但不适用于 7.3.1

dbtype        version
------------------------
PostgreSQL     7.3.1
Oracle         11.2.0.4.0
Oracle         12.4.5

我想要的输出

PostgreSQL 7
Oracle     11
Oracle     12

您可以将其转换为数组:

Select dbtype, (string_to_array(version, '.'))[1]
from the_table

或使用split_part:

Select dbtype, split_part(version, '.', 1)
from the_table