简体   繁体   English

PG :: InvalidTextRepresentation:错误:整数的无效输入语法

[英]PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer

I am doing a "IN" query using prepared statements on rails. 我正在使用Rails上的预备语句进行“ IN”查询。 I am getting PG::InvalidTextRepresentation error. 我收到PG :: InvalidTextRepresentation错误。

code : 代码:

def mark_ineligible(match_ids)
  ids = match_ids.join(", ")
  result = epr("mark_matches_as_ineligible",
               "UPDATE matches SET is_eligibile=false WHERE id IN ( $1 )",
               [ids])
end

def epr(statementname, statement, params)
  connection = ActiveRecord::Base.connection.raw_connection
  begin
    result = connection.exec_prepared(statementname, params)
    return result
  rescue PG::InvalidSqlStatementName => e
    begin
      connection.prepare(statementname, statement)
    rescue PG::DuplicatePstatement => e
      # ignore since the prepared statement already exists
    end
    result = connection.exec_prepared(statementname, params)
    return result
  end
end

trying to invoke this using : 尝试使用以下方法调用此方法:

match_ids = [42, 43]
mark_ineligible match_ids
PG::InvalidTextRepresentation: ERROR:  invalid input syntax for integer: "42, 43"

    from (irb):24:in `exec_prepared'
    from (irb):24:in `rescue in epr'
    from (irb):15:in `epr'
    from (irb):8:in `mark_ineligible'
    from (irb):35

Please help here. 请在这里帮助。 I want to know why I am getting this errors and how to fix it. 我想知道为什么会出现此错误以及如何解决。

Thanks, 谢谢,

mark_ineligible should look as follows: mark_ineligible应该如下所示:

def mark_ineligible(match_ids)
    result = epr("mark_matches_as_ineligible",
           "UPDATE matches SET is_eligibile=false WHERE id IN ( $1 )", match_ids)
end

And when you call mark_ineligible , pass an array as argument: 当您调用mark_ineligible ,将一个数组作为参数传递:

mark_ineligible(match_ids)  #=>match_ids = [42,43]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PG :: InvalidTextRepresentation:错误:整数的无效输入语法:“ aaa” - PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: “aaa” heroku:PG :: InvalidTextRepresentation:错误:整数的无效输入语法:“” - heroku: PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: “” ActiveRecord::Enum - PG::InvalidTextRepresentation:错误:整数输入语法无效: - ActiveRecord::Enum - PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: Friendly_id PG :: InvalidTextRepresentation:错误:整数的无效输入语法: - Friendly_id PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: PG :: InvalidTextRepresentation:ERROR:整数的输入语法无效:“M” - PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: “M” InvalidTextRepresentation:错误:整数的无效输入语法:“ all” - InvalidTextRepresentation: ERROR: invalid input syntax for integer: “all” Rails迁移 - PG ::错误:错误:整数的输入语法无效:“” - Rails Migration - PG::Error: ERROR: invalid input syntax for integer: “” PG错误:尝试销毁时整数的无效输入语法 - PG ERROR: invalid input syntax for integer when trying to destroy Rails -PG :: InvalidTextRepresentation:错误:格式不正确的数组文字 - Rails -PG::InvalidTextRepresentation: ERROR: malformed array literal PG :: InvalidDatetimeFormat:错误:类型为date的输入语法无效:“” - PG::InvalidDatetimeFormat: ERROR: invalid input syntax for type date: “”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM