【发布时间】:2021-07-08 17:04:28
【问题描述】:
我在一个看起来像这样的列中有这些不同的条目
[{'bus': '008', 'device': '002', 'bDeviceClass': '0 (Defined at Interface level)', 'iSerial': '3 30J155001549',... }]
我想获取 iSerial 值 30J155001549 但我不确定如何在 sql 中执行此操作。非常感谢任何建议。我们使用的数据库是 Redshift。
我试过了
SELECT json_extract_path_text(
json_extract_array_element_text(device_usb,0), 'iSerial'
)
FROM table
LIMIT 1;
但是我收到了这个错误
[XX000][500310] [Amazon](500310) Invalid operation: JSON parsing error Details: ----------------------------------------------- error: JSON parsing er ...
这是一个完整的例子
[{'bus': '004', 'device': '002', 'bDeviceClass': '0 (Defined at Interface level)', 'bInterfaceClass': '3 Human Interface Device', 'bInterfaceProtocol': '2 Mouse', 'idVendor': '0x413c Dell Computer Corp.', 'idProduct': '0x301a', 'iManufacturer': '1 PixArt', 'iProduct': '2 Dell MS116 USB Optical Mouse', 'iSerial': '0', 'MaxPower': '100mA'}, {'bus': '003', 'device': '014', 'bDeviceClass': '224 Wireless', 'bInterfaceClass': '224 Wireless', 'bInterfaceProtocol': '1 Bluetooth', 'idVendor': '0x8087 Intel Corp.', 'idProduct': '0x07dc', 'iManufacturer': '0', 'iProduct': '0', 'iSerial': '0', 'MaxPower': '100mA'}, {'bus': '003', 'device': '010', 'bDeviceClass': '0 (Defined at Interface level)', 'bInterfaceClass': '3 Human Interface Device', 'bInterfaceProtocol': '0 None', 'idVendor': '0x413c Dell Computer Corp.', 'idProduct': '0x2113', 'iManufacturer': '0', 'iProduct': '2 Dell KB216 Wired Keyboard', 'iSerial': '0', 'MaxPower': '100mA'}, {'bus': '005', 'device': '002', 'bDeviceClass': '0 (Defined at Interface level)', 'bInterfaceClass': '3 Human Interface Device', 'bInterfaceProtocol': '0 None', 'idVendor': '0x0c2e Metro', 'idProduct': '0x09cf', 'iManufacturer': '1 Honeywell Imaging & Mobility', 'iProduct': '2 CCB02', 'iSerial': '8 16197B4974', 'MaxPower': '500mA'}]
【问题讨论】:
-
在询问 SQL 问题时,请始终提供 DBMS(数据库和版本),例如作为标签。函数(用于 JSON)在很大程度上取决于您使用的数据库系统。
-
@hc_dev 刚刚修改为包含数据库
-
我们要求您添加 minimal reproducible example 以显示您尝试的代码。我假设您是 SQL 和 Amazon Redshift 的新手,所以我提供了一些快速入门的答案。但是,下次请在询问之前对文档进行研究!
标签: sql amazon-redshift