Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ewBPH-0001gd-7U for pgsql-general@arkaria.postgresql.org; Wed, 14 Mar 2018 18:45:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ewBPF-0002mj-Se for pgsql-general@arkaria.postgresql.org; Wed, 14 Mar 2018 18:45:45 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ewBPF-0002lJ-9E for pgsql-general@lists.postgresql.org; Wed, 14 Mar 2018 18:45:45 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ewBPC-0005uy-6W for pgsql-general@postgresql.org; Wed, 14 Mar 2018 18:45:44 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id F3B0D20F35; Wed, 14 Mar 2018 14:45:40 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Wed, 14 Mar 2018 14:45:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=MptMl64XSpFiRd2U3S9CJTK+DwIfc Rpv3nF0i65aXIc=; b=WILwxomqSHfyuxnWUudJNv1LJ4fJxgb919mPpoEQ2tG5H tyKqqoofKcrFotf493U5oxsQa9j/w4mLVjtq4pcrTAlk/fdXdeTdGMYSCqWgp4hb vUynytVclxYwQRYdUhWb6nn2hVptwdjAMug4lpeNzUuexZx2GfilohzKc41j91Au Dw7WeqQjTOmWONnijKl2xTZk980NXliKaR5hI3/+YeKGI9dUOJmxNvlY9Cnm/N6Q pbzPIvfJ5m9gukpnOemq+l7tSqZ5Vj7BfRSXUB6h94w6x4hMyHz1hLllH2F5ITqV mUZIFPzjbb4xTnbgsgxeg4a/9P0/juDfSa08KSZFQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=MptMl6 4XSpFiRd2U3S9CJTK+DwIfcRpv3nF0i65aXIc=; b=I6jdYZVtINl5r54/2v8Wyy /ZsHy+p3lP+rbg726EIJN1pDVJRuYAPgYMmLjZxhnY4x/YQYoq5hFRUdK89IZq28 TYqeBkmzWrquxPeLmLyq5qng/VRSCYju5XMJHGnZuQhGSwEsNDKJkNY6ugOGcMIP EG78iAFbXllr/DVO8EgRCpLTRLfHGOyAvstIMmmc8p2vfreJFVAQFpHGxiXAMDOT /S1UNDG3yBgZI3/bbBMibK+9lBZf3qvTQ/b7bNHxaiuNjfA8KnTMWTr0SQY7CbYT zvlAy+RESdxIo3BhRbcncdAjxj7Df9od1EXXaP6DtWpOeNkmwoqzADEg9bp0TP+A == X-ME-Sender: Received: from [192.168.1.2] (71-35-123-124.tukw.qwest.net [71.35.123.124]) by mail.messagingengine.com (Postfix) with ESMTPA id 71C212423D; Wed, 14 Mar 2018 14:45:40 -0400 (EDT) Subject: Re: Primary key gist index? To: Jeremy Finzel Cc: Postgres General References: From: Adrian Klaver Message-ID: Date: Wed, 14 Mar 2018 11:45:39 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 03/14/2018 11:10 AM, Jeremy Finzel wrote: > > On Wed, Mar 14, 2018 at 8:33 AM, Adrian Klaver > > wrote: > > On 03/14/2018 06:19 AM, Jeremy Finzel wrote: > > Hello!  From all that I can tell, it is not possible using a > btree_gist index as a primary key.  If so, why not?  I have a > table with this gist > > > https://www.postgresql.org/docs/10/static/btree-gist.html > > > "In general, these operator classes will not outperform the > equivalent standard B-tree index methods, and they lack one major > feature of the standard B-tree code: the ability to enforce uniqueness." > > > index which truly ought to be its primary key.  as_of_date is of > range date type: > > EXCLUDE USING gist (id WITH =, as_of_date WITH &&) > > Any direction here would be much appreciated. > > Right now, I am forced to create a redundant btree index UNIQUE, > btree (id, lower(as_of_date)) in order to have a primary key on > the table. > > Thanks! > Jeremy > > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > > > Thank you for the ref.  But I don't understand how an exclusion > constraint does not have "the ability to enforce uniqueness" unless they > just mean that is the case "under the covers of postgres".  That is > exactly what it does, right?  By the definition of the exclusion index I > have above, there cannot be more than one row with the same id and > as_of_date values. https://www.postgresql.org/docs/10/static/sql-createtable.html#SQL-CREATETABLE-EXCLUDE "The EXCLUDE clause defines an exclusion constraint, which guarantees that if any two rows are compared on the specified column(s) or expression(s) using the specified operator(s), not all of these comparisons will return TRUE. If all of the specified operators test for equality, this is equivalent to a UNIQUE constraint, although an ordinary unique constraint will be faster. ..." I have always taken the above to mean that while is possible to create an EXCLUDE that enforces uniqueness that operation is internal to the EXCLUDE and is not knowable to Postgres when it is looking for a UNIQUE index. Probably because an EXCLUDE can be non-unique. > > Thanks, > Jeremy -- Adrian Klaver adrian.klaver@aklaver.com