错误42883:运算符不存在:文本/文本

时间:2019-06-10 14:14:10

标签: postgresql jsonb

运行以下查询时:

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

1 个答案:

答案 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
相关问题