简体   繁体   中英

Invalid statement with Postgres hstore and rails

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::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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM