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 9178975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:40:54+00:00 2026-06-17T17:40:54+00:00

Evening all, I am attempting to create a table that stores a series of

  • 0

Evening all,

I am attempting to create a table that stores a series of stats on web usage for my application on a daily basis (trivial things like no. new users, total visits etc.), I am currently querying these on the fly, however I would now like to start storing them partly for performance (reducing a load of aggregate querys to single lookup) and partly to allow for historic analysis.

I have come up with the follow basic schema for the table (there will be more columns than this, just to give an idea)

create table web_stats(
    web_stat_id bigserial primary key,
    date_created timestamp not null default now(),
    user_count integer not null,
    new_user_count integer not null
);
comment on table web_stats is 'Table stores statistics on web usage';

Now, I am happy to create the queries to populate the table going forward (I am using Quartz scheduler to run the queries daily)

However I am not so sure the best way to populate the table retrospectively for past dates, should I use an INSERT statement to create a blank row for every day since the application went live (about 2 years ago), then use an UPDATE to populate the blank rows? Or can this be done in one fell swoop? Can someone provide some SQL for creating the rows?

If there is anything wrong with my design assumptions please let me know!

  • 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-17T17:40:55+00:00Added an answer on June 17, 2026 at 5:40 pm

    This is how I ended up doing it

    INSERT INTO web_stats (date_created)
        SELECT DATE('2011-08-20')+x.id
        FROM generate_series(0,521) AS x(id);
    

    Where 2011-08-20 is the date the application went live, and 521 is the number of days from now until then

    This creates the empty table so that I can use the date_created field to populate the other fields using UPDATE statements

    Maybe not the most efficient method but it works

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

Sidebar

Related Questions

Evening all :) I'm looking to create a Java web application. I envisage that
Good Evening All, A client has asked that I develop a web application as
Evening all, I've written a transfer application that needs to perform an update, then
Good evening all, I've been working on an MD5 tool in C# that takes
Good Evening All, I've created the following stored procedure: CREATE PROCEDURE AddQuote -- Add
Evening all. I have the following code that I need looking into - basically
Evening all, I have a logout button that was working absolutely fine in a
Good evening all. I'm attempting to dynamically populate a select_tag call in my rails
Evening all! I have half a script that I need to change the CSS
Good evening all, I'm trying to implement jquery table sorter, all seems fine and

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.