pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Charles Clavadetscher <clavadetscher@swisspug.org>
To: Rich Shepard <rshepard@appl-ecosys.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Variable constants ?
Date: Fri, 16 Aug 2019 15:25:30 +0200
Message-ID: <e7f1b5170944e78c11564860a5973186@swisspug.org> (raw)
In-Reply-To: <alpine.LNX.2.20.1908160549020.11183@salmo.appl-ecosys.com>
References: <20190815205657.GA2593@panix.com>
	<alpine.LNX.2.20.1908151422480.13052@salmo.appl-ecosys.com>
	<11025034d9e2c2b5e0316aa1f80dfe68@swisspug.org>
	<alpine.LNX.2.20.1908160549020.11183@salmo.appl-ecosys.com>

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         |
|                           |
+---------------------------+





view thread (12+ messages)  latest in thread

Message-ID: <e7f1b5170944e78c11564860a5973186@swisspug.org>
Permalink:  ../e7f1b5170944e78c11564860a5973186@swisspug.org/
Also on:    postgresql.org/message-id/e7f1b5170944e78c11564860a5973186@swisspug.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: clavadetscher@swisspug.org, rshepard@appl-ecosys.com
  Subject: Re: Variable constants ?
  In-Reply-To: <e7f1b5170944e78c11564860a5973186@swisspug.org>
  References: <20190815205657.GA2593@panix.com> <alpine.LNX.2.20.1908151422480.13052@salmo.appl-ecosys.com> <11025034d9e2c2b5e0316aa1f80dfe68@swisspug.org> <alpine.LNX.2.20.1908160549020.11183@salmo.appl-ecosys.com> <e7f1b5170944e78c11564860a5973186@swisspug.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox