There is such a request:

select max (number::integer) from table where id = ? 

This is a text field (as it was originally decided to make for convenience, so it went). But here's a bad luck - if someone inserts a '-' or '/', '\', and so on, then of course the exception will be sent to ::integer .

How can you implement a query so that it is the maximum number of fields that do not contain these signs?

    1 answer 1

    PostgreSQL has regulars. Try this:

     select max (number::integer) from table where id = ? and number !~ '[^0-9]' 

    The sampling rate will of course pass, but you will not get an exception when converting to INT