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 1kN0Wq-0007C6-QN for pgsql-general@arkaria.postgresql.org; Mon, 28 Sep 2020 21:17:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kN0Wp-0000nJ-OD for pgsql-general@arkaria.postgresql.org; Mon, 28 Sep 2020 21:17:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kN0Wp-0000nC-GV for pgsql-general@lists.postgresql.org; Mon, 28 Sep 2020 21:17:47 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kN0Wn-000295-Ad for pgsql-general@lists.postgresql.org; Mon, 28 Sep 2020 21:17:47 +0000 Received: by mail-pf1-x442.google.com with SMTP id o20so2320083pfp.11 for ; Mon, 28 Sep 2020 14:17:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=8Vsz7bMEwhI3xKfYtrxdDHp8UOj+qj5qAOiPCYA3X28=; b=jx++8HgHdVUp8pHWlaymOv2Pco/Fp8QdqurIMXggyMCtOM2eH3r4y4pTd1xQT5rGcU 24iPwldGIOOQhT6LzI3TvAUORddtRTaaRMmWISvY/54vD8akpmKVspnj5SulkdmkHVXl hu+1zU+vXnp1aoxwf0COMFycpZmhGzXP50NckppddAtLLo+XLe4fl77sNUKH+0kwcBt+ nHLiXF0le4rd43e/jqzaPZimd4jJI2xek+mE2tr18RtuE9pnpd+OWq5So9Vkg2/7cVju hZhAfL7jab0iE4+Xs+rHylUlTsQKfjkw7iSkKDSwYeqlRoC2v4FTvxM5owjyc/mD7T2O sXQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=8Vsz7bMEwhI3xKfYtrxdDHp8UOj+qj5qAOiPCYA3X28=; b=pCQjOsfb73xrjeRYzCuMjQHgwlIIMdE/HKoWuM2zf7JzJfGVYLrOTcc+8L0fhs3ABO Bch8QX+rLf9HJfP/692h9g+QtPRy/zOoLrUmSAJp0ilaxsA5rPfGZ9FCjs9RJ2en/rO9 KgEPgsnPICsy8vPFnmbg9zHA8zYCtYEVJyWY5eV7MUaYjuDpZI90iIczPLgagx+hxsoy rSUl1gmOxHUZZK2VJ8gSXBYaNBPA8qqpDOvLLnrmwLmCw/cce0Nnd13q/RWttA/BUv1i iOo8gGey4VD4dZQQ0CKfKIDSVhwWs0sQav7quyKkg4pOn/hFCY6dFkbXD+77mM6C3nnj belw== X-Gm-Message-State: AOAM533lok4aq5Neuzh057qlnxqXa2u5aoD/0iVmTn71TD2l94ZdVz0A n75gB0pHhUc50iaAZCmIjvSNHjyMhod2Ng== X-Google-Smtp-Source: ABdhPJyaDotPpmYuiwGgDb6AmHEETso8kqL4lJjN0MKmJp0eBEeVVH49LWVHIss1GSRfZcUm6W85dA== X-Received: by 2002:a17:902:a712:b029:d1:cbf4:c583 with SMTP id w18-20020a170902a712b02900d1cbf4c583mr1359978plq.16.1601327862511; Mon, 28 Sep 2020 14:17:42 -0700 (PDT) Received: from uss-902371.ad.utah.edu ([155.98.131.4]) by smtp.gmail.com with ESMTPSA id e17sm2739052pff.6.2020.09.28.14.17.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Sep 2020 14:17:41 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) Subject: Re: DOMAIN/composite TYPE vs. base TYPE From: Rob Sargent In-Reply-To: <6198aad8-df09-569e-686b-7e32979cd7e4@freedomcircle.com> Date: Mon, 28 Sep 2020 15:17:38 -0600 Cc: pgsql-general@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <0E2C98A4-7228-4FCE-9F22-328F0543F4F0@gmail.com> References: <6198aad8-df09-569e-686b-7e32979cd7e4@freedomcircle.com> To: Joe Abbate X-Mailer: Apple Mail (2.3608.120.23.2.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Sep 28, 2020, at 3:14 PM, Joe Abbate wrote: >=20 > Hello, >=20 > I'm considering creating a TYPE for what may be called a "possibly = imprecise date" (pidate). The most obvious use is for recording dates = such as births or deaths of historical individuals, where we may know = that someone died precisely on a given year-month-day, but the birth may = only be known down to year-month or just the year (or perhaps we know = precisely the baptism date [Adam Smith], but not the actual birth, so we = want to record the former but qualified so it can be annotated on = display). Another use is for publications, like magazines that are = issued on a monthly basis or journals that are issued on a quarterly or = seasonal basis. >=20 > We currently have two instances of this kind, using a standard DATE = column plus a CHAR(1) column that encodes (on a limited basis for now) = the YMD, YM or Y level of precision, and a simple SQL function to return = a textual representation of the pidate. It would be nice to generalize = this before going further. >=20 > The first option I explored was creating a composite type with the two = attributes, but that doesn't allow specification of DEFAULTs, NOT NULL = or CHECK expressions on the precision code attribute. It seems I'd have = to create a DOMAIN first, then use DATE and that domain to create a = composite TYPE, to finally use the latter in actual tables. That = layering looks cumbersome. >=20 > Another option, which I havent't tried, is to subvert PG by creating = an empty table, since that creates a "record type", but even if possible = that would be a hack. >=20 > Finally there's the base TYPE. This entails writing some seven = functions "in C or another low-level language" (does PG support *any* = other such language?), plus installing a library with those functions in = a production environment. Doable, yes, but not very friendly either. >=20 > Am I overlooking something or is the practice of creating abstractions = in object-relational databases mostly unchanged? >=20 > Regards, >=20 > Joe >=20 >=20 just record all three fields (day, month, year) with nulls and do the = to-date as needed.