I have two columns, id integer
and version text
. I am trying to convert the strings in version
into integers so that I may select the maximum (most recent) version of the id.
However, the the first instance of the id
stores itself as the version
. Example:
id | version
---+--------
10 | '10'
as opposed to:
id | version
---+--------
10 | '10-0'
Additional rows follow the convention id: 10, version: 10-1. Etc.
How can I accomplish this? I have tried split_part()
and cast as int
. However, split_part(version, "-", 2)
will return what looks like an empty string. I have tried running this using a COALESCE(splitpart..., '0')
to no avail as it tried to read the empty field returned by the field index 2.