Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8099013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:15:53+00:00 2026-06-05T22:15:53+00:00

My app has started throwing errors when I try to save a particular class

  • 0

My app has started throwing errors when I try to save a particular class to the database. I’m not sure exactly what caused this to start happening – I’ve been having all kinds of database issues for the last few days….

In any case, my model seems to be working fine (it is properly calculating all of the before_save values), but then it tries to save to the database and blows up.

SQL (0.8ms)  INSERT INTO "portfolios" ("correlation_matrix", "created_at", "data", "mean_return", "std_dev", "updated_at", "weights") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"  [["correlation_matrix", "--- \n- - 1.0\n  - -0.4873114574375062\n- - -0.4873114574375062\n  - 1.0\n"], ["created_at", Sat, 16 Jun 2012 15:12:35 MDT -06:00], ["data", {"TSX"=>0.5, "VUSTX"=>0.5}], ["mean_return", #<BigDecimal:7fadb119b750,'0.488052381E-1',18(45)>], ["std_dev", #<BigDecimal:7fadb119b598,'0.7668705159 123244E-1',18(45)>], ["updated_at", Sat, 16 Jun 2012 15:12:35 MDT -06:00], ["weights", "--- \nTSX: 0.5\nVUSTX: 0.5\n"]]

Throws this error:

ActiveRecord::StatementInvalid: PG::Error: ERROR:  Syntax error near 'T' at position 5

I have no idea what this error means (or what this ‘T’ is…..), or even where to begin troubleshooting it…. Any help would be appreciated.

I can post whatever information might be necessary to figure this out….

Relevant migration:

  create_table :portfolios do |t|
    t.text :weights
    t.decimal :mean_return, :precision => 15, :scale => 10
    t.decimal :std_dev, :precision => 15, :scale => 10
    t.text :correlation_matrix
    t.hstore :data

    t.timestamps
  end

  execute "CREATE INDEX portfolios_gin_data_hstore ON portfolios USING GIN(data);"

Full stack trace:

    ActiveRecord::StatementInvalid: PG::Error: ERROR:  Syntax error near 'T' at position 5
: INSERT INTO "portfolios" ("correlation_matrix", "created_at", "data", "mean_return", "std_dev", "updated_at", "weights") VALUES ($1, $2, $3, $4,     $5, $6, $7) RETURNING "id"
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.    6/lib/active_record/connection_adapters/postgresql_adapter.rb:1164:in `get_last_result'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.    6/lib/active_record/connection_adapters/postgresql_adapter.rb:1164:in `exec_cache'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.    6/lib/active_record/connection_adapters/postgresql_adapter.rb:665:in `block in exec_query'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.    6/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/notifications/instrumenter.    rb:20:in `instrument'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.    6/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.    6/lib/active_record/connection_adapters/postgresql_adapter.rb:663:in `exec_query'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.    6/lib/active_record/connection_adapters/abstract/database_statements.rb:63:in `exec_insert'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.    6/lib/active_record/connection_adapters/abstract/database_statements.rb:90:in `insert'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.    6/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `insert'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/relation.rb:66:in `insert'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/persistence.rb:363:in `create'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/timestamp.rb:57:in `create'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/callbacks.rb:268:in `block in     create'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:403:in     `_run__772785567275930853__create__1186465801021498362__callbacks'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.6/lib/active_support/callbacks.rb:405:in     `__run_callback'
... 11 levels...
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/validations.rb:50:in `save'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/attribute_methods/dirty.rb:22:in     `save'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/transactions.rb:241:in `block (2     levels) in save'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/transactions.rb:295:in `block in     with_transaction_returning_status'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.    6/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/transactions.rb:208:in     `transaction'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/transactions.rb:293:in     `with_transaction_returning_status'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/transactions.rb:241:in `block in     save'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/transactions.rb:252:in     `rollback_active_record_state!'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activerecord-3.2.6/lib/active_record/transactions.rb:240:in `save'
  from (irb):33
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
  from /Users/brandon/.rvm/gems/ruby-1.9.3-p194@myapp/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
  from script/rails:6:in `require'
  from script/rails:6:in `<main>'

UPDATE 1
Some model code as requested.

macro stuff:

attr_accessible :weights

serialize :correlation_matrix
serialize :weights

has_and_belongs_to_many :securities, :uniq => true
has_and_belongs_to_many :efficient_frontiers

before_validation :format_weights_tickers, :add_securities, :validate_weights, :set_weights_in_hstore, :build_correlation_matrix, :set_mean_return, :set_standard_deviation

validates_presence_of :mean_return, :std_dev, :securities, :correlation_matrix, :weights
validates_numericality_of :mean_return, :std_dev

validate :uniqueness_of_weights 

before_destroy :check_for_dependent

scope :by_std_dev, :order => 'std_dev ASC'

anything and everything I can find to do with the HStore column
all I really use HStore for is for a search on specific tickers. This used to work… I don’t know what changed. I might have upgraded Postgres (I was fiddling around with homebrew) or potentially something changed with rails. I did try going back to 3.2.3 but I got the same error.

def self.find_by_hstore(search_key, search_value)  
  where("data @> (:key => :value)", :key => search_key.to_s, :value => search_value.to_s)
end  

def set_weights_in_hstore
  self.data = {} if self.data.nil?
  weights.each_pair {|ticker, weight| self.data[ticker.to_s] = weight}
end

I can post the entirety of the model if this is too disjointed. Let me know!

UPDATE #2 – I am getting similar errors elsewhere also….

After a simple user signup….

SQL (10.9ms)  INSERT INTO "users" ("admin", "confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "data", "email", "encrypted_password", "last_email_at", "last_sign_in_at", "last_sign_in_ip", "name", "plan", "remember_created_at", "reset_password_sent_at", "reset_password_token", "selected_portfolio_id", "sign_in_count", "unconfirmed_email", "updated_at", "verified") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23) RETURNING "id"  [["admin", false], ["confirmation_sent_at", Sat, 16 Jun 2012 20:37:07 MDT -06:00], ["confirmation_token", "7Xu15pMrV9zTNmofv8bD"], ["confirmed_at", nil], ["created_at", Sat, 16 Jun 2012 20:37:07 MDT -06:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["data", {"min_rebalance_spacing"=>90 days, "max_contact_frequency"=>7 days, "allowable_drift"=>5}], ["email", "joe@what.com"], ["encrypted_password", "$2a$10$HNUmlYmcVXbBsyZRFCAB7e8c5mf6S9UOdWr/ZCz10y5Sg4gOh8Zvq"], ["last_email_at", Sat, 16 Jun 2012 20:37:07 MDT -06:00], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["name", "Joe Blow"], ["plan", "basic"], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["reset_password_token", nil], ["selected_portfolio_id", nil], ["sign_in_count", 0], ["unconfirmed_email", nil], ["updated_at", Sat, 16 Jun 2012 20:37:07 MDT -06:00], ["verified", false]]

20:37:07 log.1          | [ef4a7d55fb30e8fb82ac6c860e674bfc] [127.0.0.1] PG::Error: ERROR:  Syntax error near 'm' at position 5

20:37:07 log.1          | : INSERT INTO "users" ("admin", "confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "data", "email", "encrypted_password", "last_email_at", "last_sign_in_at", "last_sign_in_ip", "name", "plan", "remember_created_at", "reset_password_sent_at", "reset_password_token", "selected_portfolio_id", "sign_in_count", "unconfirmed_email", "updated_at", "verified") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23) RETURNING "id"

UDPATE 3

There appears to be something funky going on with my database / user table. I get the following error during loading the environment in a migration:

rake aborted!
PG::Error: ERROR:  relation "users" does not exist
LINE 4:              WHERE a.attrelid = '"users"'::regclass
                                        ^
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc,         a.attnotnull
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"users"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:15:54+00:00Added an answer on June 5, 2026 at 10:15 pm

    I just had a similar problem, on Rails 3.2. If you’re not using Rails trunk (working towards 4.0), it doesn’t understand the hstore natively – you need to define a serialization coder (which is provided by the activerecord-postgres-hstore gem), like so:

    class Example < ActiveRecord::Base
      serialize :data, ActiveRecord::Coders::Hstore
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure what I did, but kaminari has started acting weird in my
The latest version of my app has started to crash on startup for some
How can i find out if a C# App has been started from the
I am investigating a problem with an old VB6 app which has just started
I am working on an existing ASP.NET MVC app that started small and has
My app has this one screen requires login, should I make a comment for
Say that the user has started my App and then switched off to use
This popup comes up as soon as the app is started: The program can't
I've been working on a web app lately, and Activerecord has started creeping me
I'm just getting started with git and I have a question. My app has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.