Forward ported PR 560, Fixes #333

Change included by the port is to allow range queries on table
primary key fields, using min/max
Merge pull request #337 from mhitza/pr-327

Forward ported PR 560, Fixes #333