2

I have following sql in my controller:

@tot_expense = Expense.where("strftime('%m', created_at) + 0 = ?", Time.now.strftime("%m").to_i).sum("amount")

This works fine in my development environment. But after deploying in heroku it gives me the below error while saving the record.

PG::Error: ERROR: function strftime(unknown, timestamp without time zone) does not exist

I have uncommented config.time_zone = 'UTC' in my config/application.rb file but it didnt work.

Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
Sumy
  • 49
  • 8

1 Answers1

2

You probably want to extract month from created_at field, please use extract sql function.

  @tot_expense = Expense.where("extract(month from created_at) + 0 = ?", Time.now.strftime("%m").to_i).sum("amount")
bhugo313
  • 431
  • 2
  • 6
  • Thanks it worked on heroku but not on development probably because sqlite dose not understand 'extract'.. – Sumy Nov 17 '14 at 11:17
  • @Sumy, you need to use PostgreSQL on local development, it's not good to use different databases for development and production environment. Please refer this post. http://stackoverflow.com/questions/10859186/sqlite-in-development-postgresql-in-production-why-not – bhugo313 Nov 17 '14 at 14:57