create or replace view inventory as (
		select it.upc as upc,
			b.id as batch,
			it.name as name,
			it.package as package,
			to_char(b.price, '999.99') as unitprice,
			-- It's fine to encode numerics as strings
			date(b.received at time zone 'UTC') as received,
			date(b.best_until at time zone 'UTC') as best_until,
			i.quantity as quantity,
			i."location" as "location",
			d.name as discount_name,
			d.definition::text as discount_definition
		from itemsonshelf i
			join batches b on i.batch = b.id
			join items it on it.sku = b.sku
			left join discounts d on i.discount = d.id
		where it.current = true
	)