create or replace function fetch_from_shelf(sku integer, loc integer)
  returns integer
language sql as
$$
  select
    min(itemsonshelf.id) as id
  from
    "batches"
  join
    itemsonshelf
  on
    "batches".id = itemsonshelf.batch
  where
    itemsonshelf.location = $2 and "batches".sku = $1;
$$;
