From: Tom Lane <tgl@sss.pgh.pa.us>
To: stan <stanb@panix.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Variable constants ?
Date: Thu, 15 Aug 2019 18:12:49 -0400
Message-ID: <31388.1565907169@sss.pgh.pa.us> (raw)
In-Reply-To: <20190815205657.GA2593@panix.com>
References: <20190815205657.GA2593@panix.com>
stan <stanb@panix.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, stanb@panix.com
Subject: Re: Variable constants ?
In-Reply-To: <31388.1565907169@sss.pgh.pa.us>
References: <20190815205657.GA2593@panix.com> <31388.1565907169@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox