代码之家  ›  专栏  ›  技术社区  ›  sashaaero

浮点数数组不存在PostgreSQL运算符

  •  0
  • sashaaero  · 技术社区  · 7 年前

    我的列定义是 array2 double precision[] NOT NULL .

    select *
    from test
    where ARRAY[1.1, 2.2, 3.3] <@ array2;
    

    select *
    from test
    where '{1.1, 2.2, 3.3}' <@ array2;
    

    第二个很好,但第一个给我 ERROR: operator does not exist: numeric[] <@ double precision[]

    铸造类型有帮助,但为什么没有它就不能工作?

    select *
    from test
    where ARRAY[1.1, 2.2, 3.3]::double precision[] <@ array2;
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   klin    7 年前

    语法与 array 相反,允许解析器立即解析表达式的类型:

    select '{1.2}', pg_typeof('{1.2}'), array[1.2], pg_typeof(array[1.2])
    
     ?column? | pg_typeof | array | pg_typeof 
    ----------+-----------+-------+-----------
     {1.2}    | unknown   | {1.2} | numeric[]
    (1 row)
    

    '{1.2}' unknown 并在后期应用算子时进行求解。右边操作数的类型适合,所以 已成功解析为 double prcission[]