Fixed a bug in query generation in pgsql adapter