For every pairing of platform
and semver
I'm trying to to get the second newest record as a way to support the previous app version to latest, at all times.
Here's my schema:
id, platform, semver, name
Some sample data:
I would like the query to return:
papapal, ios, 1.0.2
papapal, android, 1.0.2
foobar, ios, 1.4.0
foobar, android, 1.4.0
Notice how it's not the latest record, but the second latest record.
I can sort by semver using, but the grabbing second latest for each app is tripping me up.
SELECT id, semver
FROM app_versions
ORDER BY string_to_array(semver, '.')::int[];
Appreciate any help!