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 1iFZ5K-0000Ly-JN for pgsql-performance@arkaria.postgresql.org; Wed, 02 Oct 2019 07:30:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iFZ5I-0004TE-F0 for pgsql-performance@arkaria.postgresql.org; Wed, 02 Oct 2019 07:30:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFZ5I-0004T1-2U for pgsql-performance@lists.postgresql.org; Wed, 02 Oct 2019 07:30:04 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iFZ5F-0005Fd-Ng for pgsql-performance@lists.postgresql.org; Wed, 02 Oct 2019 07:30:02 +0000 Received: by mail-wm1-x341.google.com with SMTP id y135so4241800wmc.1 for ; Wed, 02 Oct 2019 00:30:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=5pIctplSpfm+ja7bNholyPbo2PiDAh7r6jeMz/Ci7G4=; b=rhGvaBkX/llrhEcmvvwKObgcxUGmpQa5SO8dNW50xB8jFej27sL/Uga+E5CAuAjQgu GF3fioOPiZ3O35iodNchSbWRyHoFSe5AaVnBn+zPYid/J9GeK3vXSCxldsew14UpBn3n pEjvRV3jsOpAjqD8xEfGXmntYrveTwgFqw2kMncxJqV4DP1cjAq49PcV76dCZ6f7ilIf P4SLzBCbeU5tP3zWSOfSNB757ZUxul6v69OWDuXo0ZqaJjBMhD294CQOaDJM9DzmGjB7 xROCZWPOk7mRrghAlKF4KPJx5+nzDYQPU/JqTg4yowXMuh+77Ep8DFhCY5i5flUa8qPs zLCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=5pIctplSpfm+ja7bNholyPbo2PiDAh7r6jeMz/Ci7G4=; b=cKSNtFUbZRxDCBULsVtnlLIA7S/U85oBP+fFAIWpC4MVbpP5PTNd/0J9KEE+T4ulUP S7PgaWXBoC4Nuw/bDd89jsktIpWcaEGFmXbi3n25uhTZfES/GYYQ06rNzRunUi2N/NuI E5+sLv4aG9kTJx+na8W3pwovTcNt63qEDBbbwKlwPCR+K4n+cAcdNgayBsLLa9ibSYmF 2zF4HdSyZGBb0VCjnZt70Qw8AWGs3LF8OXs5qczjpXxNTUXAgT3iHlSatKucxp377yhR Agomi6OGXnJEUiD60tsQe6yBM4H+efSY4gU0fOuBcn3sCSi00ODbhJEUlz6RYBoNocys 4N3A== X-Gm-Message-State: APjAAAX6ruHTFTrr/4gQRiq5CIQ6ObdiaWNS6jLHcpOQYGOyvjThYf5N vT5poSSS7KOmDSM3hqXOeCxwUg== X-Google-Smtp-Source: APXvYqw2MLt5qqNP3qNwg/nkUxelOhVHsdhi3yg3N0yJvn9meuIpKYZEuQED3u+UriaZfIsNw6eaDA== X-Received: by 2002:a1c:4846:: with SMTP id v67mr1633236wma.120.1570001399492; Wed, 02 Oct 2019 00:29:59 -0700 (PDT) Received: from localhost.localdomain (217-149-168-9.nat.highway.telekom.at. [217.149.168.9]) by smtp.gmail.com with ESMTPSA id q124sm8303578wma.5.2019.10.02.00.29.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2019 00:29:58 -0700 (PDT) Message-ID: Subject: Re: pg12 - partition by column that might have null values From: Laurenz Albe To: Mariel Cherkassky , pgsql-performance@lists.postgresql.org Date: Wed, 02 Oct 2019 09:29:58 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.4 (3.32.4-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Mariel Cherkassky wrote: > In PG12 I'm trying to create partitions by range on a date column > that might be null (indicates it is the most recent version of the > object). My PK has to include the partition column, therefore I'm > getting an error that I cant create a primary key with the specific > column because it has null values. > > For example : > \d object_revision > Table > "public.object_revision" > Column | Type | Collation | Nullable | > Default > -------------+-----------------------------+-----------+----------+ > ----------------------------------------------- > id | integer | | not null | > nextval('mariel_dates_test_id_seq'::regclass) > end_time | timestamp without time zone | | | > object_hash | text | | | > Indexes: > "id_pk" PRIMARY KEY, btree (id) > > Lets say that the same object (object_hash) can have many revisions, > the end_time is the time it was last updated. I'm trying to create > this table as a range partition on the end_time. However, when I try > to add the pk I'm getting an error : > ALTER TABLE object_revision ADD CONSTRAINT > object_revision_id_end_time PRIMARY KEY (id,end_time); > ERROR: column "end_time" contains null values > > does someone familiar with a workaround ? I know that in postgresql > as part of the primary key definition unique and not null constraints > are enforced on each column and not on both of them. However, this > might be problematic with pg12 partitions.. Can "end_time" ever be modified? If yes, it is a bad choice for a partitioning column. If the NULL in "end_time" is meant to signify "no end", use the value "infinity" instead of NULL. Then you can define the column as NOT NULL. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com