
synopsis:

	List of packages which can be updated

description:

	Prints list of packages which can be updated for all systems in spacewalk.
	Shows only the newest package version available for upgrade.

columns:

	system_id System id
  org_id  Id of organization system belongs to
  package_name  Name of the package
  package_epoch Epoch of the package
  package_version Version of the package
  package_release Release of the package
  package_arch  Architecture of the package
	newest_epoch Version of the newest package available
  newest_version Release of the newest package available
  newest_release  Architecture of the newest package available

sql:

	select * from (
  select S.id as system_id,
    S.org_id as org_id,
    PN.name as package_name,
    OPE.epoch as package_epoch,
    OPE.version as package_version,
    OPE.release as package_release,
    PA.label as package_arch,
    NPE.epoch as newest_epoch,
    NPE.version as newest_version,
    NPE.release as newest_release
  from rhnServer S
    join rhnServerNeededCache SPC on S.id=SPC.server_id
    join rhnPackage P on SPC.package_id=P.id
    join rhnPackageName PN on P.name_id=PN.id
    join rhnServerPackage SP on SP.server_id=S.id and SP.name_id=P.name_id
    join rhnPackageArch PA on SP.package_arch_id=PA.id
    join rhnPackageEvr OPE on OPE.id=SP.evr_id
    join rhnPackageEvr NPE on NPE.id=P.evr_id
  where NPE.evr=(
    select max(PE.evr)
    from rhnServerNeededCache SPC1
      join rhnPackage P1 on SPC1.package_id=P1.id
      join rhnPackageEvr PE on P1.evr_id=PE.id
    where P1.name_id=P.name_id
      and SPC1.server_id = s.id)
  ) X
  -- where placeholder
  order by org_id, system_id
