Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hycEf-0002sf-HE for pgsql-general@arkaria.postgresql.org; Fri, 16 Aug 2019 13:25:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hycEe-00016b-D4 for pgsql-general@arkaria.postgresql.org; Fri, 16 Aug 2019 13:25:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hycEe-00016R-3F for pgsql-general@lists.postgresql.org; Fri, 16 Aug 2019 13:25:40 +0000 Received: from gandalf.net-wizard.org ([2a01:4f8:172:2a5c::5]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hycEa-0001ej-FO for pgsql-general@postgresql.org; Fri, 16 Aug 2019 13:25:38 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.net-wizard.org (Postfix) with ESMTP id 4C83A80FBD; Fri, 16 Aug 2019 15:25:34 +0200 (CEST) X-Virus-Scanned: Gentoo amavisd-new at aragorn Received: from aragorn.net-wizard.org ([127.0.0.1]) by localhost (aragorn.net-wizard.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id YVvE3xY5WxMu; Fri, 16 Aug 2019 15:25:30 +0200 (CEST) Received: from webmail.net-wizard.org (localhost [IPv6:::1]) by gandalf.net-wizard.org (Postfix) with ESMTP id B0364800A7; Fri, 16 Aug 2019 15:25:30 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Fri, 16 Aug 2019 15:25:30 +0200 From: Charles Clavadetscher To: Rich Shepard Cc: pgsql-general@postgresql.org Subject: Re: Variable constants ? In-Reply-To: References: <20190815205657.GA2593@panix.com> <11025034d9e2c2b5e0316aa1f80dfe68@swisspug.org> User-Agent: Roundcube Webmail/1.4-rc1 Message-ID: X-Sender: clavadetscher@swisspug.org Organization: Swiss PostgreSQL Users Group List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-08-16 14:50, Rich Shepard wrote: > On Fri, 16 Aug 2019, Charles Clavadetscher wrote: > >> Another way to keep a history is using a daterange instead of two >> columns for start and end date. Something like >> >> create table labor_rate_mult ( >> rate real primary_key, >> validity daterange not null >> ) > > Charles, > > Just out of curiosity, what is the range for a rate that is still > current? > Does it change every day? > > Regards, > > Rich Hi Rich That would be a range with an empty upper bound. Let's say that the rate is valid since 2019-08-14 then the range would look like [2019-08-14,) A query to find the current rate would look like: SELECT rate FROM labor_rate_mult WHERE validity @> CURRENT_DATE; Here you can find documentation on the range types (cool stuff I believe): https://www.postgresql.org/docs/11/rangetypes.html Regards Charles -- Charles Clavadetscher Swiss PostgreSQL Users Group Treasurer Neugasse 84 CH – 8005 Zürich http://www.swisspug.org +---------------------------+ | ____ ______ ___ | | / )/ \/ \ | | ( / __ _\ ) | | \ (/ o) ( o) ) | | \_ (_ ) \ ) _/ | | \ /\_/ \)/ | | \/ | | _| | | | \|_/ | | | | Swiss PostgreSQL | | Users Group | | | +---------------------------+