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 1i8nSi-0004cB-Vj for pgsql-general@arkaria.postgresql.org; Fri, 13 Sep 2019 15:26:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i8nSg-0007Kg-Pm for pgsql-general@arkaria.postgresql.org; Fri, 13 Sep 2019 15:26:14 +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 1i8nSg-0007KS-Aa for pgsql-general@lists.postgresql.org; Fri, 13 Sep 2019 15:26:14 +0000 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i8nSd-0004Af-2f for pgsql-general@lists.postgresql.org; Fri, 13 Sep 2019 15:26:13 +0000 Received: by mail-io1-xd44.google.com with SMTP id f12so63326123iog.12 for ; Fri, 13 Sep 2019 08:26:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=T7mYteOVg4k2r1aszOA6uVfGLXzCnNsRL9g1mt6UT88=; b=RNRRINhSn1LsypHs1l398IjRtnUBvGisQ0w3wcWFMlhRAKoBBIQwW7u5amQ6Lr6682 113F73VcMf22vTuOgLQQ4Vzslh7wW+E6CRnMXTYcVHM6243f2LocoyccUP48VAMp0Xr5 73PmhHck7YTV9TgQckmPeTFPr3stKulm1PI915XkL4YEhA5hcPWsR7yflhL54+vdaY4U ChBpb7qkpGDdoucGiVrJ+vEsCVAmijZPfwgfsH/mKdEEwBtzBy20+o94bopJeF3xwT61 FcwpwuHYg7GvLZIKeXqiiK6ogYiUC2vybn13NoJJg3BLaLjhDBBocHK1i+2qaMp7+R+H pqgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=T7mYteOVg4k2r1aszOA6uVfGLXzCnNsRL9g1mt6UT88=; b=IsIsnUUg2OooqylDPcTijQ5/EMDfKYXD6TBKcBkGYySoGlm8AE1NlIlRUpZhWb+EC5 /I2BjF30NnO5jmejJsZCrXyGwkUZmdOKLX/X4dyn8Y1SHR+Y6MGow0iXWZYHhNi7wNya yLBvzdoFE5cM/QT6nd1999ydGiZ5BfEkaPIMkzAxxSd/lYyjcnpZJiu4n0Q+8DVAo8+e an0IuNufdE/0IWgpbXHG3Aa7qj3MiQrOUOxJXck82dWkl1F8GG89WS5ydYq2N60oOLXn Ong8GQYat3y8QxyWV5seInHGIfRvAkQPjIB1HWLJPhCNsJgT9S2coHv67jaPcK9AbF8d gD3g== X-Gm-Message-State: APjAAAUTz/9sSiLLD0UQzIaDdFK/6XO/mtd1G+Zf/oCDUipd9YeiSoHi US6HWem7Dn+NK2yoblqxymCNX8gRKYw= X-Google-Smtp-Source: APXvYqyXqPkh+ygx4a7sLCPXxYePuNPeNZ9pe8mQY6gqQviQYgCsKmnlLNvhNO3tXshLVZmSPN1JdA== X-Received: by 2002:a63:3c08:: with SMTP id j8mr9464622pga.72.1568387968583; Fri, 13 Sep 2019 08:19:28 -0700 (PDT) Received: from [192.168.2.101] (static-50-53-109-254.bvtn.or.frontiernet.net. [50.53.109.254]) by smtp.googlemail.com with ESMTPSA id a17sm28452754pfc.26.2019.09.13.08.19.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Sep 2019 08:19:27 -0700 (PDT) Subject: Re: How to handle things that change over time? To: pgsql-general@lists.postgresql.org References: <20190913095733.GD22033@panix.com> From: Paul Jungwirth Message-ID: Date: Fri, 13 Sep 2019 08:19:27 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190913095733.GD22033@panix.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 9/13/19 2:57 AM, stan wrote: > > I am working on a system that will support internal bossiness work for a > company. Periodicly things will change in their "world". Oh this is my favorite topic. :-) It's a common problem, although solutions don't seem to be well-known in the programming community. Typically you'd use start/end times on your table, as you suggested. Postgres is a great RDBMS for this since it has range types and exclusion constraints. The SQL:2011 standard also has temporal primary keys, foreign keys, SELECTs, and UPDATE/DELETEs, and we're working on adding those too. But your use case sounds easy to build even without those extra features. Here is a talk I gave this summer about temporal features in Postgres: https://github.com/pjungwir/postgres-temporal-talk And here is an annotated bibliography to the main writings & tools out there, including some projects that might help you implement what you want in Postgres: https://illuminatedcomputing.com/posts/2017/12/temporal-databases-bibliography/ > In another scenario, a column of the employee table is the pay rate. > Obviously this will change over time, also. It does not appear to me > that this lends itself to this same treatment, as most of the data > associated with a given employee, is fairly static, and if I add an > entire row, just because the pay rate changed, this looks overly > complex. Normally people would indeed just add another row. I wouldn't call it complex (especially compared to the alternatives), but maybe a little wasteful. The Date/Darwen/Lorentzos book gives a lot of attention to avoiding the problem though. Essentially you'd adopt a sixth-normal form where each attribute (column) gets its own table. Good luck. I'm always happy to talk about temporal databases if you like. :-) Yours, -- Paul ~{:-) pj@illuminatedcomputing.com