you could do something like this:
if { [ catch {
db_foreach queryname {select * from table where attribute ~* :value} {
...
}
} errMsg ] } {
if {[string match {*Invalid regular expression*} $errMsg]} {
...
}
}
note that you should use a bind variable (the :value) rather than $value. Also, checking for the error message in the string is a little fragile (and you have to have a version
of nspostgres that returns it, and if yours doesn't you should get the one in sourceforge).