使用Postgres hstore和rails的语句无效

时间:2022-01-18 22:23:39

I am using the activerecord-postgres-hstore gem with rails 3.2. I have setup hstore and when I try and save any data I get the error:

我使用的activerecord-postgres-hstore gem与rails 3.2。我有安装hstore,当我尝试保存任何数据时,我得到错误:

ActiveRecord::StatementInvalid in ProductsController#create

PG::Error: ERROR:  Syntax error near 'a' at position 4
: INSERT INTO "products" ("created_at", "name", "price", "properties", "updated_at")      
VALUES ($1, $2, $3, $4, $5) RETURNING "id"

In this case I have 'properties' defined as an hstore data type. I have seen this error with both postgresl 8.4 and 9.1. Any info appreciated.

在本例中,我将'properties'定义为hstore数据类型。我在postgresl 8.4和9.1中都见过这个错误。任何信息表示赞赏。

1 个解决方案

#1


4  

Adding the code " serialize :data, ActiveRecord::Coders::Hstore" from Rails 3.2 Postgres Save Error "ActiveRecord::StatementInvalid: PG::Error: ERROR: Syntax error near 'T' at position 5" solved my issue. I just had the wrong model name when I initially tried this as a fix.

添加代码“序列化:数据,ActiveRecord:: Hstore”from Rails 3.2 Postgres保存错误”ActiveRecord::StatementInvalid: PG::错误:错误:在“位置5”附近的语法错误“解决了我的问题”。当我最初尝试用这个作为修正时,我只是用了错误的模型名。

#1


4  

Adding the code " serialize :data, ActiveRecord::Coders::Hstore" from Rails 3.2 Postgres Save Error "ActiveRecord::StatementInvalid: PG::Error: ERROR: Syntax error near 'T' at position 5" solved my issue. I just had the wrong model name when I initially tried this as a fix.

添加代码“序列化:数据,ActiveRecord:: Hstore”from Rails 3.2 Postgres保存错误”ActiveRecord::StatementInvalid: PG::错误:错误:在“位置5”附近的语法错误“解决了我的问题”。当我最初尝试用这个作为修正时,我只是用了错误的模型名。