Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 864
Mark Locklear Avatar asked Mar 11 '26 12:03

Mark Locklear


1 Answers

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.

like image 179
Mark Locklear Avatar answered Mar 14 '26 09:03

Mark Locklear



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!