SELECT
  (
    (
      ((npi.nursery_id || '_' :: text) || npi.type) || '_' :: text
    ) || npi.specie_id
  ) AS id,
  sum(npi.quantity) AS quantity,
  npi.specie_id,
  npi.nursery_id,
  ns.city_id,
  npi.type
FROM
  (
    nursery_plant_inventory npi
    JOIN nursery_view ns ON ((npi.nursery_id = ns.id))
  )
GROUP BY
  npi.specie_id,
  npi.nursery_id,
  npi.type,
  ns.city_id;