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 1q6Amo-0001m8-UK for pgsql-general@arkaria.postgresql.org; Mon, 05 Jun 2023 14:02:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q6Amn-00020O-Lh for pgsql-general@arkaria.postgresql.org; Mon, 05 Jun 2023 14:02:17 +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 1q6Amn-0001zt-AT for pgsql-general@lists.postgresql.org; Mon, 05 Jun 2023 14:02:17 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1q6Amk-000LvF-VN for pgsql-general@lists.postgresql.org; Mon, 05 Jun 2023 14:02:16 +0000 Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5147dce372eso7145031a12.0 for ; Mon, 05 Jun 2023 07:02:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20221208.gappssmtp.com; s=20221208; t=1685973733; x=1688565733; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=SdGEcPkuUsaEMjAgrbIwXSaaqTRBuc3UXlT1LP0kJA4=; b=xfHXnL6+cRN9mXWgwKxlZqF+gae3q9Xq5zmDEyCtyqr4WIh4M+UqaJccxiFeCywr5i 9UpXzWTPa49be7lSppg45n+k+rZg9g9T18Yzh6GpC1KZvLwUANulH4KwAYcVoECgFdqC Dg1ah8ynNdMtcpqeG/Vln8dQvh6A/S7QNhTshRu3xTdRe5p7ff8AAsVCjZzVixqZfQIC GqEXK3tysmAxXq3sOOrER0dYZ0XlkZdoymCoHezAhnGgOJ9dL01OWykC12ORyrohBjJB 5ipChabY+EJvZ8fuuWY7G/3c0ME3ytvQcK/DX0D+BNbjXus3nrlmZtNhb0tdh79g1J4s twVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685973733; x=1688565733; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=SdGEcPkuUsaEMjAgrbIwXSaaqTRBuc3UXlT1LP0kJA4=; b=iMKEncquneQtFRLi/7fOMhCzmLJi0oiTZPhYqKjOGItI8HDwq4AlytqpYKjiMtgECa xflXXdFLeUqHu9qxg15sHfyBrDONgjeYYnlTm4JF5YX8aYNAZAzCDpGt41l6g6Sj/La5 5yhLaSg1oiZHssL2lP88p349SnZJlV4filaDQVgidEi2kygJrlKXkK8e+Vx50Bx7zB4e +PwvsX8VaxKgMGa6hGTIriRpFyXFQ0663NCpki7LqNzqpAY6QfhN0aP5+5E9RprUrz9t 1HLbMNgTvKeKU0vMTRx29aj75UXmXxa5wbPucL1x9glJRRXf1Lc9qEU3yJXk1wc3rp1X 0CcQ== X-Gm-Message-State: AC+VfDx6he5JOKteMcD6VcZW1vzmg3ckTtA85o+CISVAEAg238UFgYSo uquH79gLbY7roQNa/UUV/NrwysP0f1pn1RfTj8I= X-Google-Smtp-Source: ACHHUZ4ebTy9LpuC0vRWgJ8A3tO042RsbByBm8IrPYRioVl6uWOZf9kcPn9T19gO0Qcco+B0r4o43A== X-Received: by 2002:a17:907:961a:b0:974:20bd:6e15 with SMTP id gb26-20020a170907961a00b0097420bd6e15mr8691730ejc.4.1685973733497; Mon, 05 Jun 2023 07:02:13 -0700 (PDT) Received: from localhost.localdomain ([2001:871:5e:6888:bdff:4d5b:3b36:4e7b]) by smtp.gmail.com with ESMTPSA id bt24-20020a170906b15800b00967004187b8sm4355069ejb.36.2023.06.05.07.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 07:02:13 -0700 (PDT) Message-ID: Subject: Re: Composite type: Primary Key and validation From: Laurenz Albe To: Lorusso Domenico , pgsql-general@lists.postgresql.org Date: Mon, 05 Jun 2023 16:02:12 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2023-06-05 at 11:49 +0200, Lorusso Domenico wrote: > I've a couple of questions about composite type. > Suppose this composite type: > CREATE TYPE my_type AS ( > =C2=A0 =C2=A0 user_ts_start My_start_timestamp, > =C2=A0 =C2=A0 user_ts_end My_end_timestamp, > =C2=A0 =C2=A0 db_ts_start My_start_timestamp, > =C2=A0 =C2=A0 db_ts_end My_end_timestamp, > =C2=A0 =C2=A0 audit_record jsonb > ); > My_start_timestamp is a domain of timestamp with default as now(). > My_end_timestamp is a domain of timestamp with default as infinite >=20 > =C2=A0=C2=A0=C2=A01. May I use user_ts_start and/or db_ts_start has part = of Primary Key of a table that=C2=A0contains a field of my_type? > =C2=A0=C2=A0=C2=A02. to add an overall check constraint on the entire com= posite type, could be a valid > approach to create a domain based on my_type and add a custom funct= ion=C2=A0to validate it? (check_my_type(VALUE)). > In this way I've a dominan of composite type=C2=A0that contain othe= rs domain... what=C2=A0do you think? Avoid using composite types as data types for a table column. It adds complexity for no clear gain. Yours, Laurenz Albe