我得到了请求的输出,该输出为我提供了我需要的所有信息。但是在输出结果中我有一个空行,但是应该将它们从输出中排除,因为它们不包含全部信息。
drXY:null
和distInM:null
-不应输出
像下面的示例一样,它们应由坐标填充
drXY:50.34982681,30.95430183 | fromXY:50.33421340,30.98074794 | distInM:2561
drXY:50.35084534,30.95514488 | fromXY:50.33421340,30.98074794 | distInM:2597
这就是我所拥有的
drXY:46.46833420,30.74011040 | fromXY:46.48067899,30.74296405 | distInM:1390
| fromXY:50.37433094,30.92993617 |
drXY:50.36543655,30.92126656 | fromXY:50.36977360,30.92906177 | distInM:735
我已经尝试过了
select substring(query from '(drXY:[0-9]+\.[0-9]+,[0-9]+\.[0-9]+)') as drxy,
substring(query from '(fromXY:[0-9]+\.[0-9]+,[0-9]+\.[0-9]+)') as fromxy,
substring(query, '(distInM:[0-9]+)') as dist
from (
select additional_data -> 'cd' ->> 'Query' as query
from stat_event where
additional_data -> 'cd' ? 'Query' and
value is null and
action = 'ProposalShown' and
created between '2019-08-04' and '2019-08-05') t;
答案 0 :(得分:1)
要使用派生值,我们可以将表达式放在CTE中,然后像正常一样使用派生列。
with (
select substring(query from '(drXY:[0-9]+\.[0-9]+,[0-9]+\.[0-9]+)') as drxy,
substring(query from '(fromXY:[0-9]+\.[0-9]+,[0-9]+\.[0-9]+)') as fromxy,
substring(query, '(distInM:[0-9]+)') as dist
from (
select additional_data -> 'cd' ->> 'Query' as query
from stat_event where
additional_data -> 'cd' ? 'Query' and
value is null and
action = 'ProposalShown' and
created between '2019-08-04' and '2019-08-05'
) t
) as derived
select *
from derived
where drxy is not null
and fromxy is not null
and dist is not null;
注意:如果query
在插入和更新时分解成其派生列,事情将会变得更加容易和快捷。