Kaka DBA Kaka DBA - 3 years ago 122
SQL Question

round a version in PostgreSQL

I need to round off a version column , Round() works well with decimal, But doesn't works on something like 7.3.1

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


My desired output

PostgreSQL 7
Oracle 11
Oracle 12

Answer Source

You could convert it to an array:

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

Or use split_part:

Select dbtype, split_part(version, '.', 1)
from the_table
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download