zoukankan      html  css  js  c++  java
  • python3操作pgsql报错:No operator matches the given name and argument type(s),You might need to add explicit type casts

    python操作数据库时报错了,报错内容为“No operator matches the given name and argument type(s),You might need to add explicit type casts”,原因在于字段格式不正确。

    举例:

    import psycopg2
    
    
    code='123'
    # 建立连接
    conn=psycopg2.connect(database="",user="",password="",host="",port="")
    # 游标
    cur=conn.cursor()
    # query
    query=("select ... where code = %s" %code)
    # 执行query
    cur.execute(query)
    # 获取结果
    rows=cur.fetchall()
    print(rows)
        

    运行结果:报错,提示"No operator matches the given name and argument type(s),You might need to add explicit type casts"

    修改query为query=("select ... where code = cast (%s as VARCHAR)" %code)

    运行结果:查询成功

    报错原因在于字段格式错误,可通过cast(字段  as VARCHAR)指定格式为VARCHAR。

    本文转载https://blog.csdn.net/yongshiaoteman/article/details/81095864

  • 相关阅读:
    我开博客了,啦啦啦.
    cf593div2
    Comet OJ
    cf591div2abc
    cfround586ac
    cf589div2
    cf573div2
    Codeforces Round #569 (Div. 2)
    uva11729 水题
    luogu1984 [SDOI2008] 烧水问题
  • 原文地址:https://www.cnblogs.com/jinziguang/p/13386567.html
Copyright © 2011-2022 走看看