(PDB-660) Fix testing for not(regexp) match case

This includes a race condition we found, and a type casting problem in
postgresql.