Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnlmq-0006Iy-5G for pgsql-general@arkaria.postgresql.org; Tue, 23 Jun 2020 16:28:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jnlmo-0005o8-QB for pgsql-general@arkaria.postgresql.org; Tue, 23 Jun 2020 16:28:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnlmo-0005mg-I3 for pgsql-general@lists.postgresql.org; Tue, 23 Jun 2020 16:28:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnlmi-0005MF-An for pgsql-general@postgresql.org; Tue, 23 Jun 2020 16:28:37 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 05NGSUwY2153719; Tue, 23 Jun 2020 12:28:30 -0400 From: Tom Lane To: David Gauthier cc: Postgres General Subject: Re: getting daily stats for event counts In-reply-to: References: Comments: In-reply-to David Gauthier message dated "Tue, 23 Jun 2020 12:04:50 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2153717.1592929710.1@sss.pgh.pa.us> Date: Tue, 23 Jun 2020 12:28:30 -0400 Message-ID: <2153718.1592929710@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk David Gauthier writes: > I have a table which logs the inception of an event with an > "incept_datetime" (timestamptz) field. I want to know how many events > occurred per day from one date to the next using midnight as a marker for > each day reported. The end result should be something like... > 2019-06-23 44 > 2019-06-24 18 > 2019-06-25 38 > etc... > Is there a query that can do this ? Something involving GROUP BY date_trunc('day', incept_datetime) ought to do it, possibly with some fooling around required depending on what definition of "midnight" you want to use. regards, tom lane