简体   繁体   English

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

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

I have followed all suggestions from similar questions but none has solved my problem. 我遵循了类似问题的所有建议,但没有一个解决了我的问题。 I want to change the field gl_code from string to integer and have tried the following: 我想将字段gl_codestring更改为integer ,并尝试了以下操作:

class ChangeCategoryGlCode < ActiveRecord::Migration
  def change
    # Category.all.each { |cat| cat.update(gl_code: cat.gl_code.to_i) }
    Category.where("gl_code IS NULL OR gl_code = ''").update_all({gl_code: '0'})
    # change_column :categories, :gl_code, :integer, using: 'gl_code::integer'
    change_column :categories, :gl_code, 'integer USING CAST(gl_code AS integer)'
  end
end

But nothing seems to work. 但是似乎没有任何作用。 I even ssh'd to the server and run the commands manually but whenever I try to deploy it fails at rake db:migrate with the error above. 我什至ssh'd到服务器并手动运行命令,但是无论何时尝试部署,它都会在rake db:migrate失败,并出现上述错误。

Any suggestions/hints are welcome. 欢迎任何建议/提示。

Previous questrions (1) , (2) 先前的问题(1)(2)

Edit: If that matters, I am using the Apartment gem, and have tried changing the gl_code for Category for each tenant. 编辑:如果那很重要,我正在使用Apartment gem,并尝试更改每个租户的Categorygl_code

Use PL/pgSQL to find the guilty row: 使用PL / pgSQL查找有罪的行:

DO
$$DECLARE
   v_gl_code text;
   v_id bigint;
BEGIN
   FOR v_id, v_gl_code IN
      SELECT id, gl_code FROM category
   LOOP
      BEGIN
         PERFORM v_gl_code::integer;
      EXCEPTION
         WHEN OTHERS THEN
            RAISE NOTICE 'Bad value at id = %', v_id;
      END;
   END LOOP;
END;$$;

暂无
暂无

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

相关问题 PG :: InvalidTextRepresentation:错误:整数的无效输入语法 - PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer Friendly_id PG :: InvalidTextRepresentation:错误:整数的无效输入语法: - Friendly_id PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer: 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: 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 PostgreSQL错误:整数的输入语法无效 - PostgreSQL ERROR: invalid input syntax for integer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM