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
Post a Comment