在 SQL/SPSS 查询中使用 json 运算符

use of json operators inside SQL/SPSS query

我正在尝试从我从 SPSS Statistics (ODBC GET DATA) 获取的 postgresql table (eventos_detalle) 中的 jsonb 字段 (eventos) 解析和求和值jsonb_to_record 函数正在运行,但 ->> 运算符导致语法错误。我已经引用并双引了我能做的一切,但仍然可以让它发挥作用。任何评论将不胜感激。

这是从 SPSS Syntax Editor 中完全复制的代码

GET DATA
  /TYPE=ODBC
  /CONNECT='DSN=PostgreSQL30;DATABASE=informes;SERVER=10.4.0.141;PORT=5432;UID=erubio;PWD=-!7K-X,'+
    '-!o/$,:!/,J-,///!$!;SSLmode=disable;ReadOnly=0;Protocol=7.4;FakeOidIndex=0;ShowOidColumn='+
    '0;RowVersioning=0;ShowSystemTables=0;Fetch=100;UnknownSizes=0;MaxVarcharSize='+
    '255;MaxLongVarcharSize=8190;Debug=0;CommLog=0;UseDeclareFetch=0;TextAsLongVarchar='+
    '1;UnknownsAsLongVarchar=0;BoolsAsChar=1;Parse=0;ExtraSysTablePrefixes=;LFConversion='+
    '1;UpdatableCursors=1;TrueIsMinus1=0;BI=0;ByteaAsLongVarBinary=1;UseServerSidePrepare='+
    '1;LowerCaseIdentifier=0;D6=-101;XaOpt=1'
  /SQL='SELECT * FROM informes.public."eventos_detalle", jsonb_to_record(eventos)'
            ' AS x(hlc text, llc text, event text, fecha text, total real, accion text, fuente text,'
                    ' cliente text, VirtualServer text, destinationip text, eventdirection text, destinationport text),'
                    ' SUM(('eventos'->>'total')::float) AS total'
  /ASSUMEDSTRWIDTH=255

如果 ->> 确实是问题所在,而不是无效使用字符串文字而不是列标识符,则可以将 ->> 运算符替换为函数调用:

eventos ->> 'total'

可以替换为:

jsonb_extract_path_text(eventos, 'total')