postgresql 9.5 - Cast character to int in order to query properly -


i need select range of values (eg : "1", "2", "2a", "3", ...) in column these character varying must cast them int in order proper "between" evaluation.

this tried seems ignores cast, returning values corresponding numins = 1001 :

select sum(totalchiefs) totalchiefs      , sum(totalnochiefs) totalnochiefs      , sum(totalchildrens) totalchildrens      , sum(totalpeople) totalpeople nombrehabs numins = 1001 , ((numpol~e'^\\d+$')::integer between 1 , 27); 

you use substring function extract number strings.

select      sum( totalchiefs ) totalchiefs,     sum ( totalnochiefs ) totalnochiefs,     sum ( totalchildrens ) totalchildrens,     sum ( totalpeople ) totalpeople      nombrehabs      numins = 1001      , (substring(numpol '\d+')  :: integer between 1 , 27) ); 

checkout documentation @ 9.7. pattern matching


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -