Forward ported PR 560, Fixes #333

Change included by the port is to allow range queries on table
primary key fields, using min/max