【问题标题】:how to use @> operator with psycopg2如何在 psycopg2 中使用 @> 运算符
【发布时间】:2018-12-16 14:40:01
【问题描述】:

Psycopg2 不断给我以下错误:

    psycopg2.ProgrammingError: operator does not exist: numrange @> integer

    HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts

我想从我的 postgres 数据库中具有 int4range 类型的列的表中获取值(例如 1)的范围。

    select price,weight_kgs @>1 from weight_categories;

注意:当我在终端中使用代码时,代码会运行

这是我的表的结构:

      Column   |   Type   | Collation | Nullable |                       
    Default                        
    ------------+----------+-----------+----------+------------------- 
    -----------------------------------
     weight_id  | integer  |           | not null | 
    nextval('weight_categories_weight_id_seq'::regclass)
     weight_kgs | numrange |           | not null | 
     price      | integer  |           | not null | 

【问题讨论】:

    标签: python-3.x psycopg2 psql


    【解决方案1】:

    numrange 类型要求被检查的值至少有一个小数点。这个

         select price,weight_kgs @>1.0 from weight_categories;
    

    会起作用。 如果您在 python 程序中从用户那里获取价值。 您可以使用添加小数点,

           num = float(value)
    

    其中 value 可以是 1 或任何其他整数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-12
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 2018-09-16
      相关资源
      最近更新 更多