Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have a Rails API that calls a Postgresql function. The Postgresql function returns a string that includes some columns from a table. Some of these columns are timestamps with time zone. The Rails app will call this function and show it through the API.

The postgres database time zone is set to US/Eastern. The problem is the time zone in the database is set to UTC when we call the function from rails. I need to be able to set the timezone in Postgresql for the user. The only way I know to do this, is to set config.active_record.default_timezone. But I know that can only be set to either local or UTC.

Another way I can set it is by setting it when I call the postgres function, so my code becomes something like this:

ActiveRecord::Base.connection.execute("SET TIMEZONE='US/Eastern'; SELECT * FROM my_postgresql_function()")

I cannot think of anything else. Even though I know it's not advised, I would like to be able to do something like setting the default_timezone in a before action. However, I dont see a way of doing that since it has to either local or UTC.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.