运行以下查询时:
Sub demo()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "http://example.com"
IE.Visible = True
While IE.Busy
DoEvents
Wend
Set TrackID = IE.document.getElementById("masked_consumer")
TrackID.Focus
Application.SendKeys ("(574844)"), True
Application.SendKeys ("{ENTER}"), True
End Sub
我遇到以下错误:
select data from example
where (data -> 'properties' ->> 'outageCount') / (data -> 'properties' ->> 'trackedCount') > 0.01
ERROR 42883: operator does not exist: text / text
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
和outageCount
都作为整数存储在JSONB中。
我尝试使用trackedCount
进行投射,但出现以下错误:
as float
答案 0 :(得分:1)
即使该字段是JSON数字,也将以text
的形式返回(请参见json and jsonb operators):
db=# select pg_typeof(('{"foo":3}'::jsonb)->>'foo');
pg_typeof
-----------
text
(1 row)
您需要通过在表达式后附加::float
来强制转换:
db=# select pg_typeof((('{"foo":3}'::jsonb)->>'foo')::float);
pg_typeof
------------------
double precision
(1 row)
在您的情况下:
select data from example
where (data -> 'properties' ->> 'outageCount')::float / (data -> 'properties' ->> 'trackedCount')::float > 0.01