我的数据库有一个包含类似json的数据结构的列(但没有实际的json标记)它看起来像这样:
---
ID: "-2293428132623007080"
RES_ID: '0'
NUMBER: "ДЕП002М Москва-Черновцы"
TRIP_SEATS_MAP: 'true'
SHOW_PICKUP_DROPOFF: 'false'
HAS_TRANSFER: 'false'
PLACES_COUNT: '49'...
我需要从中选择HAS_TRANSFER值。参数被分隔为行,没有分隔符。有没有办法选择单独的参数值?
答案 0 :(得分:0)
一种方法是在HAS_TRANSFER:
和换行\r
with t(col) as(
select 'ID: "-2293428132623007080"
RES_ID: ''0''
NUMBER: "ДЕП002М Москва-Черновцы"
TRIP_SEATS_MAP: ''true''
SHOW_PICKUP_DROPOFF: ''false''
HAS_TRANSFER: ''false''
PLACES_COUNT: ''49'''::text
union all
select 'ID: "-2293428132623007080"
RES_ID: ''0''
NUMBER: "ДЕП002М Москва-Черновцы"
TRIP_SEATS_MAP: ''true''
SHOW_PICKUP_DROPOFF: ''false''
HAS_TRANSFER:''bla''
PLACES_COUNT: ''49'''::text
)
-- below is actual query:
select substring(col from 'HAS_TRANSFER:\s*([^\r]+)') from t