fix for postgresql adapter in rails 2.3

The code was mistakenly using defined? instead of method_defined?, and
the postgres adapter in AR 2.3 doesn't define a exec_query method, so
the alias_method was exploding.