gpt4 book ai didi

sql - 查询otrs数据库

转载 作者:行者123 更新时间:2023-11-29 13:35:33 29 4
gpt4 key购买 nike

我在从 OTRS 对 postgresql 数据库创建查询时遇到问题。我需要获取包含存储在 CMDB 中的一些数据的 Assets 列表,但我在存储数据的方式上遇到了问题。

就目前而言,此查询工作正常,但一旦我添加另一个左连接以获取更多数据,它就会一直运行而不会返回任何结果。

据我所知,问题是所有信息都包含在 xml_storage 表中,没有任何关系,因此我需要反复查询该表以获取数据。还有一种混合数据类型,在某些情况下整数存储为可变字符,这使我无法使用该值从通用目录中获取其他信息。

几天来我一直在用头撞砖墙,所以我真的很感激任何帮助

SELECT 
asset_value,
manufacturer_value,
model_value,
serial_value,
fqdn_value,
array_agg(service),
purchasedate_value,
status_value,
configitem.configitem_number,
configitem_version.name,
general_catalog.name

FROM
public.configitem_version,
public.general_catalog,
public.configitem

left join
(SELECT
xml_storage.xml_content_value AS asset_value,
xml_storage.xml_key
FROM
public.xml_storage
WHERE
xml_content_key = '[1]{''Version''}[1]{''Asset Number''}[1]{''Content''}') as select_asset on last_version_id::int = select_asset.xml_key::int

left join
(SELECT
xml_storage.xml_content_value AS manufacturer_value,
xml_storage.xml_key
FROM
public.xml_storage
WHERE
xml_content_key = '[1]{''Version''}[1]{''Manufacturer''}[1]{''Content''}' ) as select_manufacturer on last_version_id::int = select_manufacturer.xml_key::int

left join
(SELECT
xml_storage.xml_content_value AS model_value,
xml_storage.xml_key
FROM
public.xml_storage
WHERE
xml_content_key = '[1]{''Version''}[1]{''Model''}[1]{''Content''}' ) as select_model on last_version_id::int = select_model.xml_key::int

left join
(SELECT
xml_storage.xml_content_value AS serial_value,
xml_storage.xml_key
FROM
public.xml_storage
WHERE
xml_content_key = '[1]{''Version''}[1]{''SerialNumber''}[1]{''Content''}' ) as select_serial on last_version_id::int = select_serial.xml_key::int

left join
(SELECT
xml_storage.xml_content_value AS fqdn_value,
xml_storage.xml_key
FROM
public.xml_storage
WHERE
xml_content_key = '[1]{''Version''}[1]{''FQDN''}[1]{''Content''}' ) as select_fqdn on last_version_id::int = select_fqdn.xml_key::int

left join
(SELECT
link_relation.source_key AS "configitem_id",
service.name AS "service"
FROM
public.link_relation,
public.service
WHERE
link_relation.target_key::int = service.id AND
link_relation.target_object_id::int = 2 AND link_relation.source_object_id::int = 3
UNION
SELECT
link_relation.target_key AS "configitem_id",
service.name AS "service"
FROM
public.link_relation,
public.service
WHERE
link_relation.source_key::int = service.id AND
link_relation.target_object_id::int = 3 AND link_relation.source_object_id::int = 2) as select_service on configitem.id = configitem_id::int

left join
(SELECT
xml_storage.xml_content_value AS purchasedate_value,
xml_storage.xml_key
FROM
public.xml_storage
WHERE
xml_content_key = '[1]{''Version''}[1]{''PurchaseDate''}[1]{''Content''}' ) as select_purchasedate on last_version_id::int = select_purchasedate.xml_key::int

left join
(SELECT
general_catalog.name AS status_value,
general_catalog.id
FROM
public.general_catalog) as select_status on configitem.cur_depl_state_id::int = select_status.id::int

WHERE
configitem.last_version_id = configitem_version.id AND
configitem.class_id = general_catalog.id AND
(configitem.class_id = 32 OR configitem.class_id = 33)


GROUP BY
asset_value,
manufacturer_value,
model_value,
serial_value,
fqdn_value,
purchasedate_value,
status_value,
configitem.configitem_number,
configitem_version.name,
general_catalog.name

;

最佳答案

您是否可以使用 OTRS API 而不是查询?以这种方式获取数据会更容易一些。此外,ImportExport 模块允许将数据导出到 .csv 文件;根据您的需要,这可能是一个选项。

关于sql - 查询otrs数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13237579/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com