Select next or first row
You can combine the two queries:
with t as (
  select *
  from the_table 
  where id &gt; 5 
  order by id limit 1
)
select *
from t
union all
select *
from the_table
where id = 1 
and not exists (select *
                from t);

Another option is to use an OR condition:
select *
from the_table
where (id &gt; 5  or id = 1)
order by id = 1, id
limit 1  

The order by id = 1 will sort the row with id = 1 at the end and all others (where that condition is false) will be sorted by the actual id value. The disadvantage is that you need to repeat the search condition
Typically OR conditions aren't optimized well, so the first alternative might be faster.