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

  • Home
  • SEARCH
  • 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 8703719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:55:55+00:00 2026-06-13T02:55:55+00:00

When running the following query in psql I get back 7 results: SELECT generate_series(‘2012-10-14’,

  • 0

When running the following query in psql I get back 7 results:

SELECT generate_series('2012-10-14', CURRENT_DATE, interval '1 day'); # 7

However when I run the exact same query in my rails application, I get 8 results:

result = ActiveRecord::Base.connection.execute "SELECT generate_series('2012-10-14', CURRENT_DATE, interval '1 day');"
puts result.count # 8

It seems like this has something to do w/ timezones but I don’t know what the problem could be. I have the following in my application.rb

config.time_zone = 'Eastern Time (US & Canada)'

This is the same time zone setting that I have in my postgresql.conf

I’m confused at to why my rails application is adding an additional day to my results. Can anyone provide some insight?

This only seems to happen towards the end of the day (after 8PM) so this is what makes me think it’s something w/ time zone offsets.

  • 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-13T02:55:56+00:00Added an answer on June 13, 2026 at 2:55 am

    The version of generate_series that you’re using is working with timestamps, not dates. So your '2012-10-14' and current_date are getting converted to timestamp with time zones and generate_series is producing a set of timestamp with time zones; compare these:

    => select generate_series('2012-10-14', current_date, '1 day');
        generate_series     
    ------------------------
     2012-10-14 00:00:00-07
     2012-10-15 00:00:00-07
     2012-10-16 00:00:00-07
     2012-10-17 00:00:00-07
     2012-10-18 00:00:00-07
     2012-10-19 00:00:00-07
     2012-10-20 00:00:00-07
    (7 rows)
    
    => select generate_series('2012-10-14', current_date::timestamp, '1 day');
       generate_series   
    ---------------------
     2012-10-14 00:00:00
     2012-10-15 00:00:00
     2012-10-16 00:00:00
     2012-10-17 00:00:00
     2012-10-18 00:00:00
     2012-10-19 00:00:00
     2012-10-20 00:00:00
    (7 rows)
    

    The first one has time zones, the second one doesn’t.

    But, the current_date always gets converted to a timestamp with the database session’s time zone adjustment applied. The Rails session will talk to the database in UTC, your psql session is probably using ET.

    If you manually specify the current date and explicitly work with timestamps:

    select generate_series('2012-10-14'::timestamp, '2012-10-20'::timestamp, '1 day')
    

    then you’ll get the same seven results in both because there’s no time zone in sight to make a mess of things.

    The easiest way to ignore time zones is to use the integer version of generate_series and the fact that adding an integer to a date treats the integer as a number of days:

    select '2012-10-14'::date + generate_series(0, 6)
    

    That will give you the same seven days without time zone interference. You can still use the current_date (which has no time zone since SQL dates don’t have time zones) by noting that the difference between two dates is the number of days between them (an integer):

    => select '2012-10-14'::date + generate_series(0, current_date - '2012-10-14');
      ?column?  
    ------------
     2012-10-14
     2012-10-15
     2012-10-16
     2012-10-17
     2012-10-18
     2012-10-19
     2012-10-20
    (7 rows)
    

    and from Rails:

    > pp ActiveRecord::Base.connection.execute("select '2012-10-14'::date + generate_series(0, 6)").to_a
    [{"?column?"=>"2012-10-14"},
     {"?column?"=>"2012-10-15"},
     {"?column?"=>"2012-10-16"},
     {"?column?"=>"2012-10-17"},
     {"?column?"=>"2012-10-18"},
     {"?column?"=>"2012-10-19"},
     {"?column?"=>"2012-10-20"}]
    

    BTW, I hate time zones, hate and despise them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using phpMyAdmin and running the following query I get 19 registers: SELECT * FROM
I am running following query. SELECT T1.C1, T2.C2..., IF( T1.C1<>T2.C1,Changed,1) AS NewColumn From T1
I am running following query.. Select T1.* from T1 LEFT JOIN T2 ON T1.C1
I am running the following query and checking whether it returns any results and
I'm currently running the following query: SELECT * from people WHERE id = 4;
I'm running the following query SELECT ROW_NUMBER() OVER(ORDER BY [TransactionValues].[ID]) AS idx, [Transactions].[ID] AS
When running the following the query. select * from surgicals where to_char(dt_surgery ,'DD-MM-YYYY' )
I'm running the following query: SELECT * FROM all_tab_cols c LEFT JOIN all_varrays v
I'm running the following query in MYSQL select distinct straight_join cu.entryid entryid, t0.tokpos starting_position,
I am running following query to find the best winning streak for user. $sql=select

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.