Re: Variable constants ? - Mailing list pgsql-general

From Tom Lane
Subject Re: Variable constants ?
Date
Msg-id 31388.1565907169@sss.pgh.pa.us
Whole thread Raw
In response to Variable constants ?  (stan <stanb@panix.com>)
Responses RE: Variable constants ?  (Igor Neyman <ineyman@perceptron.com>)
List pgsql-general
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



pgsql-general by date:

Previous
From: Rich Shepard
Date:
Subject: Re: Variable constants ?
Next
From: Igor Neyman
Date:
Subject: RE: Variable constants ?