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 1hyNzO-0001Ht-KY for pgsql-general@arkaria.postgresql.org; Thu, 15 Aug 2019 22:12:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hyNzM-0006hv-3U for pgsql-general@arkaria.postgresql.org; Thu, 15 Aug 2019 22:12:56 +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 1hyNzL-0006Yq-Hc for pgsql-general@lists.postgresql.org; Thu, 15 Aug 2019 22:12:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1hyNzH-0000zb-GS for pgsql-general@postgresql.org; Thu, 15 Aug 2019 22:12:54 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x7FMCno4031389; Thu, 15 Aug 2019 18:12:49 -0400 From: Tom Lane To: stan cc: pgsql-general@postgresql.org Subject: Re: Variable constants ? In-reply-to: <20190815205657.GA2593@panix.com> References: <20190815205657.GA2593@panix.com> Comments: In-reply-to stan message dated "Thu, 15 Aug 2019 16:56:57 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31387.1565907169.1@sss.pgh.pa.us> Date: Thu, 15 Aug 2019 18:12:49 -0400 Message-ID: <31388.1565907169@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk stan writes: > Failing a better way is there some way I can limit this table to only allow > one row to exist? I was recently reminded of a cute trick for that: make a unique index on a constant. regression=# create table consts(f1 int, f2 int); CREATE TABLE regression=# create unique index consts_only_one on consts((1)); CREATE INDEX regression=# insert into consts values(1,2); INSERT 0 1 regression=# insert into consts values(3,4); ERROR: duplicate key value violates unique constraint "consts_only_one" DETAIL: Key ((1))=(1) already exists. Shepard's nearby advice about keeping some history is probably a better plan though. regards, tom lane