Код:
SELECT split_part(hosts.host::text, ' '::text, 1) AS op,
hosts.hostid AS id,
reverse(split_part(hosts.description, 'SN:'::text, 2)) AS serial,
split_part(split_part(hosts.description, ','::text, 1), ':'::text, 2) AS model,
hosts.host AS hostname,
ip.ip,
uint.clock::abstime::TIMESTAMP WITHOUT TIME zone AS datetime,
CURRENT_DATE - '1 day'::INTERVAL DAY AS date_values,
uint.value AS count_copy,
CASE
WHEN items.name::text = 'Счётчик копий'::text THEN 'page_copy'::text
WHEN items.name::text = 'Счётчик напечатанных страниц'::text THEN 'page_counter'::text
ELSE NULL::text
END AS TYPE
FROM interface ip,
hosts hosts,
items items,
history_uint uint
WHERE hosts.hostid = items.hostid
AND hosts.hostid = ip.hostid
AND items.itemid = uint.itemid
AND uint.clock = ( SELECT MAX(os2.clock) AS MAX FROM history_uint os2 WHERE os2.itemid = uint.itemid AND os2.clock >= CAST(EXTRACT(epoch FROM (CURRENT_DATE - INTERVAL '5' DAY)) AS INTEGER))
AND (items.name::text = ANY (ARRAY['Счётчик копий'::CHARACTER VARYING, 'Счётчик напечатанных страниц'::CHARACTER VARYING]::text[]))
AND items.key_::text !~~ '%{#SNMPINDEX}%'::text
AND uint.clock >= CAST(EXTRACT(epoch FROM (CURRENT_DATE - INTERVAL '5' DAY)) AS INTEGER);