Hi David, sorry, absolutely forgot about important stuff like version. Original problem has been found on 9.4.9, but I was able to reproduce it on 10rc1.
localhost/postgres=# select version(); version ───────────────────────────────────────────────────────────────────────────────────────────────────────────────── PostgreSQL 10rc1 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609, 64-bit (1 row)